PC Review


Reply
Thread Tools Rate Thread

Async programming, windows forms, and releasing resources

 
 
Ernie B
Guest
Posts: n/a
 
      26th Aug 2003
I have a windows forms application that needs to contact a
web service. I want to do so asynchronously--and have done
so with few problems, in fact. The only problem is that, if
my connection times out, I want the process to abort. I also
want to make sure that I discard my resources properly. Will
the following code do the trick, or are there hidden "gotchas"
in it? What would be a better solution?


private delegate void SetComposerNameDelegate(string composerName);

private void SetComposerName(string composerName){
m_txtResult.Text = composerName;
}

private void m_btnGetComposer_Click(object sender, EventArgs args){
//Composer: the Composer web service
Composer compService = new Composer();
AsyncCallback cb = new AsyncCallback(GetComposerCallback);
IAsyncResult ar = compService.BeginGetName(3, null, null);
ar.AsyncWaitHandle.WaitOne(new TimeSpan(0, 0, 10), true);
if (ar.IsCompleted){
string composerName = compService.EndGetName(ar);
this.Invoke(new SetComposerNameDelegate(SetComposerName),
new object[]{composerName});
} else {
MessageBox.Show("Timed out!");
}
compService.Dispose();
}

eb

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Async windows programming =?Utf-8?B?TWFyayBTdGVnYQ==?= Microsoft Dot NET Framework Forms 2 22nd Feb 2005 12:57 PM
RE: Async Programming in asp .Net page as Windows Forms Steven Cheng[MSFT] Microsoft ASP .NET 2 14th Aug 2004 08:59 AM
Re: Async Programming in asp .Net page as Windows Forms bruce barker Microsoft ASP .NET 0 12th Aug 2004 08:46 PM
Async Programming in asp .Net page as Windows Forms =?Utf-8?B?U2FsYW1FbGlhcw==?= Microsoft Dot NET 0 12th Aug 2004 06:45 PM
Async web service call not releasing memory Ian L Microsoft Dot NET Framework 0 27th Oct 2003 03:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:17 PM.