c# - Assign work in backgroundworker_DoWork() according to condition -


in winform application,i want use single backgroundworker (or may 1 each form) different tasks on different events. eg: search, loading data in grid, opening new forms, sending emails, file transfer etc.

how can manage in backgroundworker_dowork() , backgroundworker_runworkercompleted() events?

what optimum way/ best practice this?

usually, end caling worker parameter, this:

backgroundworker.runworkerasync(<some argument here>); 

then inside dowork method, can retrieve argument e.argument, , according argument is, know want it.

if don't need argument else, can make enum values need, search, load , forth , pass in, , check value inside dowork choose want do. remember have cast enum inside dowork since e.argument object.

regarding runworkercompleted, can populate e.result value inside dowork, , retrieve inside runworkercompleted method well.

this best way of doing it, , thread safe way.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -