Click here to Skip to main content
15,909,440 members
Home / Discussions / C#
   

C#

 
GeneralRe: How Do I Write A "Binary" File? Pin
That Asian Guy7-May-08 11:16
That Asian Guy7-May-08 11:16 
QuestionSaving/Loading settings from Windows Service Pin
jchalfant7-May-08 9:48
jchalfant7-May-08 9:48 
AnswerRe: Saving/Loading settings from Windows Service Pin
jchalfant8-May-08 3:05
jchalfant8-May-08 3:05 
QuestionWaiting for other threads Pin
Roger Alsing7-May-08 8:56
Roger Alsing7-May-08 8:56 
AnswerRe: Waiting for other threads Pin
Gareth H7-May-08 9:03
Gareth H7-May-08 9:03 
GeneralRe: Waiting for other threads Pin
Roger Alsing7-May-08 10:08
Roger Alsing7-May-08 10:08 
AnswerRe: Waiting for other threads Pin
User 66587-May-08 9:03
User 66587-May-08 9:03 
AnswerRe: Waiting for other threads Pin
Broken Bokken7-May-08 9:19
Broken Bokken7-May-08 9:19 
My standard model for multithreading (in a windows app) is to create a a wait form. You can put a progress bar or a label or whatever you want to use. For my threads I use the System.ComponentModel.BackgroundWorker. I'll briefely explain the basics.

My code will create the BackgroundWorker and set up the method it will need to run.

C#
BackgroundWorker myWorker = new BackgroundWorker();
myWorker.DoWork += new DoWorkEventHandler(myWorker_DoWork);


The method passed in looks like this
C#
private void myWorker_DoWork(object sender, DoWorkEventArgs e)
{
   //...
}


My WaitForm accepts the BackgroundWorker as a parameter to the constructor.

My WaitForm accepts the background worker as an input parameter. You can set up the worker in the WaitForm to handle progress changed events to modify the message and even a progress bar in the wait form. Also, you will want to set the RunWorkerCompleted event and make it close the WaitForm.

Then, append this below the first block of code.

C#
WaitForm waiting = new WaitForm(myWorker);
waiting.ShowDialog();


By using ShowDialog you are forcing the current thread to wait until the dialog is done. Because the worker is working the dialog won't close until myWorker_DoWork completes.

Also, this is another good approach which I have used on a few applications.

Broken Bokken

You can't carry out a ninja-style assasination dressed as an astronaut. It's the luminous fabric; too visible. - Tripod

The story of your fighting is a poem of two words: YOU SUCK.

GeneralRe: Waiting for other threads Pin
Roger Alsing7-May-08 10:06
Roger Alsing7-May-08 10:06 
GeneralRe: Waiting for other threads Pin
Spacix One7-May-08 10:35
Spacix One7-May-08 10:35 
GeneralRe: Waiting for other threads Pin
Roger Alsing7-May-08 11:12
Roger Alsing7-May-08 11:12 
GeneralRe: Waiting for other threads Pin
GuyThiebaut7-May-08 10:51
professionalGuyThiebaut7-May-08 10:51 
GeneralRe: Waiting for other threads Pin
Spacix One7-May-08 11:01
Spacix One7-May-08 11:01 
QuestionLooking for HELPFUL information on my event log issues Pin
LongRange.Shooter7-May-08 7:25
LongRange.Shooter7-May-08 7:25 
AnswerRe: Looking for HELPFUL information on my event log issues [modified] Pin
DaveyM697-May-08 8:57
professionalDaveyM697-May-08 8:57 
QuestionCannot create an instance of the abstract class or interface 'Excel.Application Pin
Dominic Burford7-May-08 5:14
professionalDominic Burford7-May-08 5:14 
AnswerRe: Cannot create an instance of the abstract class or interface 'Excel.Application Pin
Giorgi Dalakishvili7-May-08 5:21
mentorGiorgi Dalakishvili7-May-08 5:21 
AnswerRe: Cannot create an instance of the abstract class or interface 'Excel.Application Pin
MarkB7777-May-08 13:07
MarkB7777-May-08 13:07 
QuestionRemoting in dot net Pin
ilango gandhi7-May-08 5:07
ilango gandhi7-May-08 5:07 
AnswerRe: Remoting in dot net Pin
led mike7-May-08 5:14
led mike7-May-08 5:14 
AnswerRe: Remoting in dot net Pin
Cranky7-May-08 5:33
Cranky7-May-08 5:33 
AnswerRe: Remoting in dot net Pin
Abhijit Jana7-May-08 5:55
professionalAbhijit Jana7-May-08 5:55 
AnswerRe: Remoting in dot net Pin
leckey7-May-08 6:41
leckey7-May-08 6:41 
QuestionText Ticker Pin
KBou7-May-08 4:59
KBou7-May-08 4:59 
AnswerRe: Text Ticker Pin
Christian Graus7-May-08 12:01
protectorChristian Graus7-May-08 12:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.