Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Why the "RunWorkerCompleted" never comes after pressing ENTER?

Reply
 
Old 08-04-2009   #1 (permalink)
senglory


 
 

Why the "RunWorkerCompleted" never comes after pressing ENTER?

using System;
using System.ComponentModel ;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;


namespace Retriever
{
class Program
{
static void Main(string[] args)
{
BackgroundWorker bw = new BackgroundWorker();
bw.WorkerSupportsCancellation = true;


bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
bw.RunWorkerAsync();
Console.WriteLine("Press ENTER to exit...");
Console.ReadLine();
bw.CancelAsync();
Thread.Sleep(5000);
}

static void bw_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
if (e.Cancelled )
cls.Suspend ();
}

static void bw_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i < 10000; i++){ Thread.Sleep(1000); Console.WriteLine(i);
if (e.Cancel){e.Result = "done"; return ;}} }
}
}



If to hit Entar after running the bw_RunWorkerCompleted() will be never
invoked. Why?


My System SpecsSystem Spec
Old 08-04-2009   #2 (permalink)
Family Tree Mike


 
 

Re: Why the "RunWorkerCompleted" never comes after pressing ENTER?

senglory wrote:
Quote:

> using System;
> using System.ComponentModel ;
> using System.Collections.Generic;
> using System.Linq;
> using System.Text;
> using System.Threading;
> using System.Reflection;
>
>
> namespace Retriever
> {
> class Program
> {
> static void Main(string[] args)
> {
> BackgroundWorker bw = new BackgroundWorker();
> bw.WorkerSupportsCancellation = true;
>
>
> bw.DoWork += new DoWorkEventHandler(bw_DoWork);
> bw.RunWorkerCompleted += new
> RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
> bw.RunWorkerAsync();
> Console.WriteLine("Press ENTER to exit...");
> Console.ReadLine();
> bw.CancelAsync();
> Thread.Sleep(5000);
> }
>
> static void bw_RunWorkerCompleted(object sender,
> RunWorkerCompletedEventArgs e)
> {
> if (e.Cancelled )
> cls.Suspend ();
> }
>
> static void bw_DoWork(object sender, DoWorkEventArgs e)
> {
> for (int i = 0; i < 10000; i++){ Thread.Sleep(1000); Console.WriteLine(i);
> if (e.Cancel){e.Result = "done"; return ;}} }
> }
> }
>
>
>
> If to hit Entar after running the bw_RunWorkerCompleted() will be never
> invoked. Why?
>
Please don't multipost. You can include multiple groups in a single
message so everyone sees the responses independent of the group they
first see it. I responded in microsoft.public.dotnet.framework with a
question regarding the declaration of the object cls.

--
Mike
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Empty error message when pressing "Send/Receive" in Windows Mail Vista mail
"The "'z" enter" Vista Error Vista General
HOW TO: Vista, change IE7 CTRL + ENTER shortcut to ".com" Vista General
Is there anyway to make a "secure" drive, that you must enter a password to view files? Vista General
Annoying RDP - Get rid of the "Enter your credentials"/ delete cac Vista account administration


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46