Hi everyvody, i was asking on the c# general forum on msdn for a big doubt that i have.
I have a form inside a update panel with 2 textbox, 1 label, and 2 buttons, Async button, and Sync button, what i want is: i will click in a Async Button, and his request will start, during this request, i want set my textbox1 value equals a "test", and
before this request over, i want click on Sync button, and my textbox2 will be get value from textbox 1, and after the Async request is done, label will be set to 'Asynchronous'.
In msdn, a lot of people telling of the only to do this is with AJAX, but i have NO IDEA, how make this work.
The way that i was tried is that below.
protected async void btnAsync_Click(object sender, EventArgs e)
{
ExecutarPassosAssincronos();
}
protected void btnSync_Click(object sender, EventArgs e)
{
ExecutarPassosSincronos();
}
private void Wait()
{
Thread.Sleep(3000);
}
private async void ExecutarPassosAssincronos()
{
txtAsync.Text = "TESTE";
await TaskEx.Run(() => Wait());
await TaskEx.Run(() => Wait());
// TaskEx.Run will schedule on a background thread here...
await TaskEx.Run(() => DoAsynchronousWork());
// Just call this directly after your last await:
PassoTresAssincrono();
}
private void DoAsynchronousWork()
{
// Do your "work" on the background thread
Thread.Sleep(1000);
}
private void ExecutarPassosSincronos()
{
txtSync.Text = txtAsync.Text;
}
// This isn't running on the UI thread anymore
private void PassoTresAssincrono()
{
lblResultado.Text = "Assíncrono";
}
norkk
Member
29 Points
30 Posts
sync call while async request executing
Feb 27, 2012 12:46 PM|LINK
Hi everyvody, i was asking on the c# general forum on msdn for a big doubt that i have.
I have a form inside a update panel with 2 textbox, 1 label, and 2 buttons, Async button, and Sync button, what i want is: i will click in a Async Button, and his request will start, during this request, i want set my textbox1 value equals a "test", and before this request over, i want click on Sync button, and my textbox2 will be get value from textbox 1, and after the Async request is done, label will be set to 'Asynchronous'.
In msdn, a lot of people telling of the only to do this is with AJAX, but i have NO IDEA, how make this work.
The way that i was tried is that below.
protected async void btnAsync_Click(object sender, EventArgs e) { ExecutarPassosAssincronos(); } protected void btnSync_Click(object sender, EventArgs e) { ExecutarPassosSincronos(); } private void Wait() { Thread.Sleep(3000); } private async void ExecutarPassosAssincronos() { txtAsync.Text = "TESTE"; await TaskEx.Run(() => Wait()); await TaskEx.Run(() => Wait()); // TaskEx.Run will schedule on a background thread here... await TaskEx.Run(() => DoAsynchronousWork()); // Just call this directly after your last await: PassoTresAssincrono(); } private void DoAsynchronousWork() { // Do your "work" on the background thread Thread.Sleep(1000); } private void ExecutarPassosSincronos() { txtSync.Text = txtAsync.Text; } // This isn't running on the UI thread anymore private void PassoTresAssincrono() { lblResultado.Text = "Assíncrono"; }norkk
Member
29 Points
30 Posts
Re: sync call while async request executing
Feb 27, 2012 05:03 PM|LINK
anyone can help?
Song-Tian - ...
All-Star
43697 Points
4304 Posts
Microsoft
Re: sync call while async request executing
Mar 01, 2012 07:05 AM|LINK
Hi,
Duplicate post to:http://forums.asp.net/t/1774678.aspx.
Feedback to us
Develop and promote your apps in Windows Store
chetan.sarod...
All-Star
65729 Points
11138 Posts
Re: sync call while async request executing
Mar 02, 2012 02:26 AM|LINK
http://msdn.microsoft.com/en-us/magazine/cc164128.aspx
http://www.codeproject.com/Articles/10370/Processing-Long-Running-Tasks-With-Asynchronous-Ha
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.