Asyncronous Threading Code Block?

P

Pug Fugly

I have been using asynchronous threading to handle the button actions
on my form (the ones that need to make database calls anyways). I am
curious if anyone has found a way to make the calls more generic? Is
it possible to structure the code so that you don't have to create the
delegate, BeginAction(), EndAction(), and ActionCallback() functions
for every single action that I want to handle? Especially since the
only thing different about them is the main calling method name.

Thanks,
Slavisa
 
A

AlexS

Hi, Pug

You can consider to create one delegate, which will be passed parameter
defining function to perform. Then all event handlers will call same
delegate and delegate itself will decide what do to.

HTH
Alex
 
T

Tom Shelton

I have been using asynchronous threading to handle the button actions
on my form (the ones that need to make database calls anyways). I am
curious if anyone has found a way to make the calls more generic? Is
it possible to structure the code so that you don't have to create the
delegate, BeginAction(), EndAction(), and ActionCallback() functions
for every single action that I want to handle? Especially since the
only thing different about them is the main calling method name.

Thanks,
Slavisa

You could build a class to encapsulate this. It could take a delegate
and invoke it asyncrounously, and then notify you when done via events.
Actually, in the next version of .NET there is a BackgroundWorker
component that basically does this for you - but it wouldn't be to
difficult to write a component that would handle this for you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top