views:

307

answers:

5

Hello,

I want to start a process (calling another program), currently the external program takes time (it is normal)!

but it freezes my GUI I saw allot of examples and I'm learning, it is hard to figure it out, trying to read and learn threading, but it is not that easy (at least for me) and good simple tutorial or code sample?

cheers

+1  A: 

This one is very good tutorial on Threading. It's easy, shows lots of examples (from simple to more complicated and should give you a nice start.

MadBoy
+5  A: 

Here is a link showing how to use an asynchronous method. http://www.codeproject.com/KB/cs/AsyncMethodInvocation.aspx

You can use the asynchronous method to start the process, and it won't freeze the gui while it starts up.

void Your_Method()
{
   //Start process here
}


MethodInvoker myProcessStarter= new MethodInvoker(Your_Method);

myProcessStarter.BeginInvoke(null, null);

MethodInvoker Description

Kevin
.Invoke() is not asynchronous. .BeginInvoke()/.EndInvoke() pair is. Yes?
Jesse C. Slicer
Yeah I missed that. Typing too fast.
Kevin
A: 

I think this website gives you pretty good idea about how to call external processes:

http://blogs.msdn.com/csharpfaq/archive/2004/06/01/146375.aspx

Threading is something completely different, take a look at the MSDN library for more information about threading.

+1  A: 

BackgroundWorker was designed for exactly this kind of scenario.

See MSDN.

It provides useful methods for signalling (both ways) that don't require you to marshall calls back to the UI thread yourself.

Or use the Task Parallel Library...

Byron Ross
A: 

Use this:

declare at top:

BackgroundWorker backgroundWorker1 = new System.ComponentModel.BackgroundWorker();

then in form_load:

          backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
            backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
            backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);

after which:

backgroundWorker1.RunWorkerAsync(someArg); // this calls  backgroundWorker1_DoWork(....


    // This event handler is where the actual,
    // potentially time-consuming work is done.
    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
    }
callisto