Re: BackgroundWorker and Nunit

Keith Woods <[email protected]> Wed, 24 Sep 2008 04:12:33 -0700 (PDT)
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <[email protected]>
--===============1339275186360869297==
Content-Type: multipart/alternative; boundary="0-1227559037-1222254753=:50408"

--0-1227559037-1222254753=:50408
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Here is similar code to that below, however using SynchronizationContext, s=
ame result :( =0A=0Ausing System;=0Ausing System.Collections.Generic;=0Ausi=
ng System.Linq;=0Ausing System.Text;=0Ausing NUnit.Core;=0Ausing NUnit.Fram=
ework;=0Ausing System.Threading;=0A=0Anamespace NunitBackgroundWorker=0A{=
=0A    [TestFixture]=0A    public class BackgroundTester=0A    {=0A        =
[Test]=0A        public void TestSyncContext()=0A        {=0A            ne=
w SyncContext().BackgroundTask_Run();=0A=0A            Thread.Sleep(5000);=
=0A=0A            Console.WriteLine();=0A        }=0A    }=0A}=0A=0A=0Ausin=
g System;=0Ausing System.Collections.Generic;=0Ausing System.Linq;=0Ausing =
System.Text;=0Ausing System.ComponentModel;=0Ausing System.Reflection;=0Aus=
ing System.Threading;=0Ausing System.Windows.Threading;=0A=0Anamespace Nuni=
tBackgroundWorker=0A{=0A    public class SyncContext=0A    {=0A        Sync=
hronizationContext _context =3D null;=0A=0A        public SyncContext()=0A =
       {=0A            int dispatcherHash =3D Dispatcher.CurrentDispatcher.=
Thread.GetHashCode();=0A            bool isBackGround =3D Dispatcher.Curren=
tDispatcher.Thread.IsBackground;=0A            int id =3D Dispatcher.Curren=
tDispatcher.Thread.ManagedThreadId;=0A            ApartmentState thread_sta=
te =3D Thread.CurrentThread.GetApartmentState();=0A            Console.Writ=
eLine("ctor " + MethodInfo.GetCurrentMethod().Name);=0A            Console.=
WriteLine("     DispatcherHash:{0}, IsBackground:{1}, Id:{2}, ThreadState:{=
3}", dispatcherHash, isBackGround, id, thread_state);=0A=0A            _con=
text =3D SynchronizationContext.Current;=0A            if (_context =3D=3D =
null)=0A            {=0A                _context =3D new SynchronizationCon=
text();=0A                SynchronizationContext.SetSynchronizationContext(=
_context);=0A            }=0A        }=0A=0A        void BackgroundTask_Pro=
gressChanged(object state)=0A        {=0A            int dispatcherHash =3D=
 Dispatcher.CurrentDispatcher.Thread.GetHashCode();=0A            bool isBa=
ckGround =3D Dispatcher.CurrentDispatcher.Thread.IsBackground;=0A          =
  int id =3D Dispatcher.CurrentDispatcher.Thread.ManagedThreadId;=0A       =
     ApartmentState thread_state =3D Thread.CurrentThread.GetApartmentState=
();=0A            Console.WriteLine(MethodInfo.GetCurrentMethod().Name + st=
ate.ToString());=0A            Console.WriteLine("     DispatcherHash:{0}, =
IsBackground:{1}, Id:{2}, ThreadState:{3}", dispatcherHash, isBackGround, i=
d, thread_state);            =0A        }=0A=0A        private void Backgro=
undTaskRunner()=0A        {=0A            int dispatcherHash =3D Dispatcher=
.CurrentDispatcher.Thread.GetHashCode();=0A            bool isBackGround =
=3D Dispatcher.CurrentDispatcher.Thread.IsBackground;=0A            int id =
=3D Dispatcher.CurrentDispatcher.Thread.ManagedThreadId;=0A            Apar=
tmentState thread_state =3D Thread.CurrentThread.GetApartmentState();=0A   =
         Console.WriteLine(MethodInfo.GetCurrentMethod().Name);=0A         =
   Console.WriteLine("     DispatcherHash:{0}, IsBackground:{1}, Id:{2}, Th=
readState:{3}", dispatcherHash, isBackGround, id, thread_state);=0A=0A     =
       _context.Post(BackgroundTask_ProgressChanged, "25%done");=0A        =
    Thread.Sleep(1000);=0A            _context.Post(BackgroundTask_Progress=
Changed, "50%done");=0A            Thread.Sleep(1000);=0A            _conte=
xt.Post(BackgroundTask_ProgressChanged, "75%done");=0A            Thread.Sl=
eep(1000);=0A            _context.Post(BackgroundTask_ProgressChanged, "100=
%done");=0A            Thread.Sleep(1000);=0A            _context.Post(Back=
groundTaskCompleted, "100%done");=0A        }=0A=0A        void BackgroundT=
askCompleted(object state)=0A        {=0A            int dispatcherHash =3D=
 Dispatcher.CurrentDispatcher.Thread.GetHashCode();=0A            bool isBa=
ckGround =3D Dispatcher.CurrentDispatcher.Thread.IsBackground;=0A          =
  int id =3D Dispatcher.CurrentDispatcher.Thread.ManagedThreadId;=0A       =
     ApartmentState thread_state =3D Thread.CurrentThread.GetApartmentState=
();=0A            Console.WriteLine(MethodInfo.GetCurrentMethod().Name);=0A=
            Console.WriteLine("     DispatcherHash:{0}, IsBackground:{1}, I=
d:{2}, ThreadState:{3}", dispatcherHash, isBackGround, id, thread_state);=
=0A        }=0A=0A        public void BackgroundTask_Run()=0A        {=0A  =
          int dispatcherHash =3D Dispatcher.CurrentDispatcher.Thread.GetHas=
hCode();=0A            bool isBackGround =3D Dispatcher.CurrentDispatcher.T=
hread.IsBackground;=0A            int id =3D Dispatcher.CurrentDispatcher.T=
hread.ManagedThreadId;=0A            ApartmentState thread_state =3D Thread=
.CurrentThread.GetApartmentState();=0A            Console.WriteLine(MethodI=
nfo.GetCurrentMethod().Name);=0A            Console.WriteLine("     Dispatc=
herHash:{0}, IsBackground:{1}, Id:{2}, ThreadState:{3}", dispatcherHash, is=
BackGround, id, thread_state);=0A=0A            ThreadStart threadStart =3D=
 new ThreadStart(BackgroundTaskRunner);=0A            Thread newThread =3D =
new Thread(threadStart);=0A            newThread.Start();=0A        }=0A   =
 }=0A}=0A =0A=0A=0A----- Original Message ----=0AFrom: Keith Woods <keith.w=
[email protected]>=0ATo: [email protected]=0ASent: Wednesda=
y, 24 September, 2008 10:22:28=0ASubject: [Nunit-users] BackgroundWorker an=
d Nunit=0A=0A=0AHi Everyone=0A =0AI=E2=80=99ve been=0Atrying to test some c=
ode that uses a background worker. The issues I=E2=80=99m having=0Ais that =
my test appears to NOT report progress on the same thread that created=0Ath=
e background worker. For tests that involve Dependency objects (WPF) the ca=
ll=0Aback needs to happen on the same thread.=0A =0AI have a=0Asample appli=
cation using BackgroundWorker (this is below) for one test and=0ASynchroniz=
ationContext for another, both are reporting back onto another=0Athread, no=
t the correct one.  =0A =0AUsing nunit=0AGUI I=E2=80=99ve explicitly set th=
e test to run in the STA ApartmentState.=0AUsing nunit=0Aconsole I=E2=80=99=
ve specified /nothread flag=0A =0ANothings=0Aappears to be working. I=E2=80=
=99m either misunderstanding the functionality provided=0Aby BackgroundWork=
er/SynchronizationContext, incorrectly using nunit, or it=E2=80=99s a=0Abug=
 in nunit.=0A =0AAny help=0Awould be much appreciated, =0A =0ACheers=0A =0A=
Keith=0A =0Ap.s. Here=0Ais the test with the background worker:=0A =0Ausing=
System;=0AusingSystem.Collections.Generic;=0AusingSystem.Linq;=0AusingSyste=
m.Text;=0AusingNUnit.Core;=0AusingNUnit.Framework;=0AusingSystem.Threading;=
=0A =0AnamespaceNunitBackgroundWorker=0A{=0A    [TestFixture]=0A    public =
class BackgroundTester=0A    {=0A        [Test]=0A        public void TestB=
ackgroundWorker()=0A        {=0A            new Background().RunBackgroundW=
orker();=0A =0A            Thread.Sleep(5000);=0A =0A            Console.Wr=
iteLine();=0A        }=0A}=0A =0AusingSystem;=0AusingSystem.Collections.Gen=
eric;=0AusingSystem.Linq;=0AusingSystem.Text;=0AusingSystem.ComponentModel;=
=0AusingSystem.Reflection;=0AusingSystem.Threading;=0AusingSystem.Windows.T=
hreading;=0A =0AnamespaceNunitBackgroundWorker=0A{=0A    public class Backg=
round=0A    {=0A        private BackgroundWorker _worker =3D null;=0A =0A  =
      public Background()=0A        {=0A            Console.WriteLine("ctor=
=0A" + MethodInfo.GetCurrentMethod().Name);=0A =0A           =0AInitializeB=
ackgoundWorker();=0A        }=0A =0A        private void InitializeBackgoun=
dWorker()=0A        {=0A            int dispatcherHash =3D Dispatcher.Curre=
ntDispatcher.Thread.GetHashCode();=0A            bool isBackGround =3D Disp=
atcher.CurrentDispatcher.Thread.IsBackground;=0A            int id =3D Disp=
atcher.CurrentDispatcher.Thread.ManagedThreadId;=0A            ApartmentSta=
te thread_state =3D Dispatcher.CurrentDispatcher.Thread.GetApartmentState()=
;=0A            Console.WriteLine(MethodInfo.GetCurrentMethod().Name);=0A  =
          Console.WriteLine("    =0ADispatcherHash:{0}, IsBackground:{1}, I=
d:{2}, ThreadState:{3}",=0AdispatcherHash, isBackGround, id, thread_state);=
=0A =0A           =0A_worker =3D new BackgroundWorker();=0A           =0A_w=
orker.DoWork +=3D new DoWorkEventHandler(ProcessPhotosWorker_DoWork);=0A   =
        =0A_worker.RunWorkerCompleted +=3D new RunWorkerCompletedEventHandl=
er(ProcessPhotosWorker_RunWorkerCompleted);=0A        =0A   _worker.Progres=
sChanged +=3D new ProgressChangedEventHandler(ProcessPhotosWorker_ProgressC=
hanged);=0A           =0A_worker.WorkerReportsProgress =3D true;=0A        =
}=0A =0A        void ProcessPhotosWorker_ProgressChanged(object sender, Pro=
gressChangedEventArgs e)=0A        {=0A            int dispatcherHash =3D D=
ispatcher.CurrentDispatcher.Thread.GetHashCode();=0A            bool isBack=
Ground =3D Dispatcher.CurrentDispatcher.Thread.IsBackground;=0A            =
int id =3D Dispatcher.CurrentDispatcher.Thread.ManagedThreadId;=0A     =0A =
     ApartmentState thread_state =3D Dispatcher.CurrentDispatcher.Thread.Ge=
tApartmentState();=0A            Console.WriteLine(MethodInfo.GetCurrentMet=
hod().Name=0A+ e.UserState.ToString());=0A            Console.WriteLine("  =
  =0ADispatcherHash:{0}, IsBackground:{1}, Id:{2}, ThreadState:{3}",=0Adisp=
atcherHash, isBackGround, id, thread_state);=0A        }=0A =0A        priv=
ate void ProcessPhotosWorker_DoWork(object sender, DoWorkEventArgs e)=0A   =
     {=0A            int dispatcherHash =3D Dispatcher.CurrentDispatcher.Th=
read.GetHashCode();=0A            bool isBackGround =3D Dispatcher.CurrentD=
ispatcher.Thread.IsBackground;=0A            int id =3D Dispatcher.CurrentD=
ispatcher.Thread.ManagedThreadId;=0A            ApartmentState thread_state=
 =3D Dispatcher.CurrentDispatcher.Thread.GetApartmentState();=0A           =
 Console.WriteLine(MethodInfo.GetCurrentMethod().Name);=0A            Conso=
le.WriteLine("    =0ADispatcherHash:{0}, IsBackground:{1}, Id:{2}, ThreadSt=
ate:{3}",=0AdispatcherHash, isBackGround, id, thread_state);=0A =0A        =
   =0A_worker.ReportProgress(25, "25%done");=0A            Thread.Sleep(100=
0);=0A           =0A_worker.ReportProgress(50, "50%done");=0A            Th=
read.Sleep(1000);=0A           =0A_worker.ReportProgress(75, "75%done");=0A=
            Thread.Sleep(1000);=0A           =0A_worker.ReportProgress(100,=
 "100%done");=0A        }=0A =0A        void ProcessPhotosWorker_RunWorkerC=
ompleted(object sender, RunWorkerCompletedEventArgs e)=0A        {=0A      =
      int dispatcherHash =3D Dispatcher.CurrentDispatcher.Thread.GetHashCod=
e();=0A            bool isBackGround =3D Dispatcher.CurrentDispatcher.Threa=
d.IsBackground;=0A            int id =3D Dispatcher.CurrentDispatcher.Threa=
d.ManagedThreadId;=0A            ApartmentState thread_state =3D Dispatcher=
.CurrentDispatcher.Thread.GetApartmentState();=0A            Console.WriteL=
ine(MethodInfo.GetCurrentMethod().Name);=0A            Console.WriteLine(" =
   =0ADispatcherHash:{0}, IsBackground:{1}, Id:{2}, ThreadState:{3}",=0Adis=
patcherHash, isBackGround, id, thread_state);=0A        }=0A =0A        pub=
lic void RunBackgroundWorker()=0A        {=0A            int dispatcherHash=
 =3D Dispatcher.CurrentDispatcher.Thread.GetHashCode();=0A            bool =
isBackGround =3D Dispatcher.CurrentDispatcher.Thread.IsBackground;=0A      =
      int id =3D Dispatcher.CurrentDispatcher.Thread.ManagedThreadId;=0A   =
         ApartmentState thread_state =3D Dispatcher.CurrentDispatcher.Threa=
d.GetApartmentState();=0A            Console.WriteLine(MethodInfo.GetCurren=
tMethod().Name);=0A            Console.WriteLine("    =0ADispatcherHash:{0}=
, IsBackground:{1}, Id:{2}, ThreadState:{3}",=0AdispatcherHash, isBackGroun=
d, id, thread_state);=0A =0A            =0A_worker.RunWorkerAsync("TestData=
");=0A        }=0A    }=0A}=0A=0A=0A      
--0-1227559037-1222254753=:50408
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><head><style type=3D"text/css"><!-- DIV {margin:0px;} --></style></he=
ad><body><div style=3D"font-family:tahoma, 'new york', times, serif;font-si=
ze:12pt"><div>Here is similar code to that below, however using=C2=A0Synchr=
onizationContext, same result :(=C2=A0</div><div><br></div><div><div>using =
System;</div><div>using System.Collections.Generic;</div><div>using System.=
Linq;</div><div>using System.Text;</div><div>using NUnit.Core;</div><div>us=
ing NUnit.Framework;</div><div>using System.Threading;</div><div><br></div>=
<div>namespace NunitBackgroundWorker</div><div>{</div><div>=C2=A0=C2=A0 =C2=
=A0[TestFixture]</div><div>=C2=A0=C2=A0 =C2=A0public class BackgroundTester=
</div><div>=C2=A0=C2=A0 =C2=A0{</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0=
[Test]</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0public void TestSyncConte=
xt()</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0{</div><div>=C2=A0=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0new SyncContext().BackgroundTask_Run();</=
div><div><br></div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Thre=
ad.Sleep(5000);</div><div><br></div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0
 =C2=A0Console.WriteLine();</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0}</d=
iv><div>=C2=A0=C2=A0 =C2=A0}</div><div>}</div><div><br></div><div><br></div=
></div><div>using System;</div><div>using System.Collections.Generic;</div>=
<div>using System.Linq;</div><div>using System.Text;</div><div>using System=
.ComponentModel;</div><div>using System.Reflection;</div><div>using System.=
Threading;</div><div>using System.Windows.Threading;</div><div><br></div><d=
iv>namespace NunitBackgroundWorker</div><div>{</div><div>=C2=A0=C2=A0 =C2=
=A0public class SyncContext</div><div>=C2=A0=C2=A0 =C2=A0{</div><div>=C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0SynchronizationContext _context =3D null;</div><=
div><br></div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0public SyncContext()</d=
iv><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0{</div><div>=C2=A0=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0int dispatcherHash =3D Dispatcher.CurrentDispatc=
her.Thread.GetHashCode();</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0bool isBackGround =3D Dispatcher.CurrentDispatcher.Thread.IsBackg=
round;</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int id =3D
 Dispatcher.CurrentDispatcher.Thread.ManagedThreadId;</div><div>=C2=A0=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ApartmentState thread_state =3D Threa=
d.CurrentThread.GetApartmentState();</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0Console.WriteLine("ctor " + MethodInfo.GetCurrentMethod=
().Name);</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Console.=
WriteLine(" =C2=A0 =C2=A0 DispatcherHash:{0}, IsBackground:{1}, Id:{2}, Thr=
eadState:{3}", dispatcherHash, isBackGround, id, thread_state);</div><div><=
br></div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_context =3D S=
ynchronizationContext.Current;</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0if (_context =3D=3D null)</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0{</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0_context =3D new SynchronizationContext();</div><div>=
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Synchronizatio=
nContext.SetSynchronizationContext(_context);</div><div>=C2=A0=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0}</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0}<=
/div><div><br></div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0void BackgroundTa=
sk_ProgressChanged(object state)</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=
=A0{</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int
 dispatcherHash =3D Dispatcher.CurrentDispatcher.Thread.GetHashCode();</div=
><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool isBackGround =3D =
Dispatcher.CurrentDispatcher.Thread.IsBackground;</div><div>=C2=A0=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int id =3D Dispatcher.CurrentDispatcher.T=
hread.ManagedThreadId;</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0ApartmentState thread_state =3D Thread.CurrentThread.GetApartmentStat=
e();</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Console.Write=
Line(MethodInfo.GetCurrentMethod().Name + state.ToString());</div><div>=C2=
=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Console.WriteLine(" =C2=A0 =C2=
=A0 DispatcherHash:{0}, IsBackground:{1}, Id:{2}, ThreadState:{3}", dispatc=
herHash, isBackGround, id, thread_state); =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0}</div><div><br></div=
><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0private void BackgroundTaskRunner()<=
/div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0{</div><div>=C2=A0=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0int dispatcherHash =3D Dispatcher.CurrentDispatc=
her.Thread.GetHashCode();</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0bool isBackGround =3D
 Dispatcher.CurrentDispatcher.Thread.IsBackground;</div><div>=C2=A0=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int id =3D Dispatcher.CurrentDispatcher.T=
hread.ManagedThreadId;</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0ApartmentState thread_state =3D Thread.CurrentThread.GetApartmentStat=
e();</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Console.Write=
Line(MethodInfo.GetCurrentMethod().Name);</div><div>=C2=A0=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0Console.WriteLine(" =C2=A0 =C2=A0 DispatcherHash:{0=
}, IsBackground:{1}, Id:{2}, ThreadState:{3}", dispatcherHash, isBackGround=
, id, thread_state);</div><div><br></div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0_context.Post(BackgroundTask_ProgressChanged, "25%done"=
);</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Thread.Sleep(10=
00);</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_context.Post=
(BackgroundTask_ProgressChanged, "50%done");</div><div>=C2=A0=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0Thread.Sleep(1000);</div><div>=C2=A0=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_context.Post(BackgroundTask_ProgressChanged=
, "75%done");</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Thre=
ad.Sleep(1000);</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
 =C2=A0_context.Post(BackgroundTask_ProgressChanged, "100%done");</div><div=
>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Thread.Sleep(1000);</div><d=
iv>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_context.Post(BackgroundT=
askCompleted, "100%done");</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0}</di=
v><div><br></div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0void BackgroundTaskC=
ompleted(object state)</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0{</div><d=
iv>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int dispatcherHash =3D Di=
spatcher.CurrentDispatcher.Thread.GetHashCode();</div><div>=C2=A0=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool isBackGround =3D Dispatcher.CurrentDisp=
atcher.Thread.IsBackground;</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0int id =3D Dispatcher.CurrentDispatcher.Thread.ManagedThreadId;</=
div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ApartmentState thre=
ad_state =3D Thread.CurrentThread.GetApartmentState();</div><div>=C2=A0=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Console.WriteLine(MethodInfo.GetCurre=
ntMethod().Name);</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
Console.WriteLine(" =C2=A0 =C2=A0 DispatcherHash:{0}, IsBackground:{1}, Id:=
{2}, ThreadState:{3}", dispatcherHash, isBackGround, id,
 thread_state);</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0}</div><div><br>=
</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0public void BackgroundTask_Run(=
)</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0{</div><div>=C2=A0=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int dispatcherHash =3D Dispatcher.CurrentDis=
patcher.Thread.GetHashCode();</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0bool isBackGround =3D Dispatcher.CurrentDispatcher.Thread.IsBa=
ckground;</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int id =
=3D Dispatcher.CurrentDispatcher.Thread.ManagedThreadId;</div><div>=C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ApartmentState thread_state =3D Th=
read.CurrentThread.GetApartmentState();</div><div>=C2=A0=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0Console.WriteLine(MethodInfo.GetCurrentMethod().Nam=
e);</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Console.WriteL=
ine(" =C2=A0 =C2=A0 DispatcherHash:{0}, IsBackground:{1}, Id:{2}, ThreadSta=
te:{3}", dispatcherHash, isBackGround, id, thread_state);</div><div><br></d=
iv><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ThreadStart threadSt=
art =3D new ThreadStart(BackgroundTaskRunner);</div><div>=C2=A0=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Thread newThread =3D new
 Thread(threadStart);</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0newThread.Start();</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0}</div>=
<div>=C2=A0=C2=A0 =C2=A0}</div><div>}</div><div>=C2=A0</div><div style=3D"f=
ont-family:tahoma, new york, times, serif;font-size:12pt"><br><div style=3D=
"font-family:times new roman, new york, times, serif;font-size:12pt">----- =
Original Message ----<br>From: Keith Woods &lt;[email protected]><br=
>To: [email protected]<br>Sent: Wednesday, 24 September, 20=
08 10:22:28<br>Subject: [Nunit-users] BackgroundWorker and Nunit<br><br><di=
v style=3D"font-family:tahoma, 'new york', times, serif;font-size:12pt;"><d=
iv><p class=3D"MsoNormal"><span lang=3D"EN-AU" style=3D"">Hi Everyone</span=
></p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU" style=3D""> =C2=A0<=
/span></p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU" style=3D"">I=
=E2=80=99ve been=0Atrying to test some code that uses a background worker. =
The issues I=E2=80=99m having=0Ais that my test appears to NOT report progr=
ess on the same thread that created=0Athe background worker. For tests that=
 involve Dependency objects (WPF) the call=0Aback needs to happen on the sa=
me thread.</span></p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU" sty=
le=3D""> =C2=A0</span></p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU=
" style=3D"">I have a=0Asample application using BackgroundWorker (this is =
below) for one test and=0ASynchronizationContext for another, both are repo=
rting back onto another=0Athread, not the correct one.=C2=A0 </span></p> =
=0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU" style=3D""> =C2=A0</span>=
</p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU" style=3D"">Using nun=
it=0AGUI I=E2=80=99ve explicitly set the test to run in the STA ApartmentSt=
ate.</span></p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU" style=3D"=
">Using nunit=0Aconsole I=E2=80=99ve specified /nothread flag</span></p> =
=0A=0A<p class=3D"MsoNormal"><b><span lang=3D"EN-AU" style=3D""> =C2=A0</sp=
an></b></p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU" style=3D"">No=
things=0Aappears to be working. I=E2=80=99m either misunderstanding the fun=
ctionality provided=0Aby BackgroundWorker/SynchronizationContext, incorrect=
ly using nunit, or it=E2=80=99s a=0Abug in nunit.</span></p> =0A=0A<p class=
=3D"MsoNormal"><span lang=3D"EN-AU" style=3D""> =C2=A0</span></p> =0A=0A<p =
class=3D"MsoNormal"><span lang=3D"EN-AU" style=3D"">Any help=0Awould be muc=
h appreciated, </span></p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU=
" style=3D""> =C2=A0</span></p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"=
EN-AU" style=3D"">Cheers</span></p> =0A=0A<p class=3D"MsoNormal"><span lang=
=3D"EN-AU" style=3D""> =C2=A0</span></p> =0A=0A<p class=3D"MsoNormal"><span=
 lang=3D"EN-AU" style=3D"">Keith</span></p> =0A=0A<p class=3D"MsoNormal"><s=
pan lang=3D"EN-AU" style=3D""> =C2=A0</span></p> =0A=0A<p class=3D"MsoNorma=
l"><span lang=3D"EN-AU" style=3D"">p.s. Here=0Ais the test with the backgro=
und worker:</span></p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU" st=
yle=3D""> =C2=A0</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span s=
tyle=3D"font-size:10.0pt;color:blue;">using</span><span style=3D"font-size:=
10.0pt;"> System;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span =
style=3D"font-size:10.0pt;color:blue;">using</span><span style=3D"font-size=
:10.0pt;"> System.Collections.Generic;</span></p> =0A=0A<p class=3D"MsoNorm=
al" style=3D""><span style=3D"font-size:10.0pt;color:blue;">using</span><sp=
an style=3D"font-size:10.0pt;"> System.Linq;</span></p> =0A=0A<p class=3D"M=
soNormal" style=3D""><span style=3D"font-size:10.0pt;color:blue;">using</sp=
an><span style=3D"font-size:10.0pt;"> System.Text;</span></p> =0A=0A<p clas=
s=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;color:blue;">usi=
ng</span><span style=3D"font-size:10.0pt;"> NUnit.Core;</span></p> =0A=0A<p=
 class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;color:blue;=
">using</span><span style=3D"font-size:10.0pt;"> NUnit.Framework;</span></p=
> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;c=
olor:blue;">using</span><span style=3D"font-size:10.0pt;"> System.Threading=
;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-si=
ze:10.0pt;"> =C2=A0</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><spa=
n style=3D"font-size:10.0pt;color:blue;">namespace</span><span style=3D"=0A=
font-size:10.0pt;"> NunitBackgroundWorker</span></p> =0A=0A<p class=3D"MsoN=
ormal" style=3D""><span style=3D"font-size:10.0pt;">{</span></p> =0A=0A<p c=
lass=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=
=A0=C2=A0 [<span style=3D"color:#2B91AF;">TestFixture</span>]</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=
=C2=A0=C2=A0=C2=A0 <span style=3D"color:blue;">public</span>=0A<span style=
=3D"color:blue;">class</span> <span style=3D"color:#2B91AF;">BackgroundTest=
er</span></span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D=
"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0 {</span></p> =0A=0A<p class=3D"MsoNo=
rmal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 [<span style=3D"color:#2B91AF;">Test</span>]</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span style=3D"color:blue;">publ=
ic</span> <span style=3D"color:blue;">void</span>=0ATestBackgroundWorker()<=
/span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size=
:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {</span></p> =0A=0A<p =
class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"=
color:blue;">new</span> <span style=3D"color:#2B91AF;">Background</span>().=
RunBackgroundWorker();</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><=
span style=3D"font-size:10.0pt;"> =C2=A0</span></p> =0A=0A<p class=3D"MsoNo=
rmal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:#2B91AF;"=
>Thread</span>.Sleep(5000);</span></p> =0A=0A<p class=3D"MsoNormal" style=
=3D""><span style=3D"font-size:10.0pt;"> =C2=A0</span></p> =0A=0A<p class=
=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:=
#2B91AF;">Console</span>.WriteLine();</span></p> =0A=0A<p class=3D"MsoNorma=
l" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 }</span></p> =0A=0A<p class=3D"MsoNormal"><span style=3D"fo=
nt-size:10.0pt;">}</span></p> =0A=0A<p class=3D"MsoNormal"><span lang=3D"EN=
-AU" style=3D""> =C2=A0</span></p> =0A=0A<p class=3D"MsoNormal" style=3D"">=
<span style=3D"font-size:10.0pt;color:blue;">using</span><span style=3D"fon=
t-size:10.0pt;"> System;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""=
><span style=3D"font-size:10.0pt;color:blue;">using</span><span style=3D"fo=
nt-size:10.0pt;"> System.Collections.Generic;</span></p> =0A=0A<p class=3D"=
MsoNormal" style=3D""><span style=3D"font-size:10.0pt;color:blue;">using</s=
pan><span style=3D"font-size:10.0pt;"> System.Linq;</span></p> =0A=0A<p cla=
ss=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;color:blue;">us=
ing</span><span style=3D"font-size:10.0pt;"> System.Text;</span></p> =0A=0A=
<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;color:blu=
e;">using</span><span style=3D"font-size:10.0pt;"> System.ComponentModel;</=
span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:=
10.0pt;color:blue;">using</span><span style=3D"font-size:10.0pt;"> System.R=
eflection;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=
=3D"font-size:10.0pt;color:blue;">using</span><span style=3D"font-size:10.0=
pt;"> System.Threading;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D"">=
<span style=3D"font-size:10.0pt;color:blue;">using</span><span style=3D"fon=
t-size:10.0pt;"> System.Windows.Threading;</span></p> =0A=0A<p class=3D"Mso=
Normal" style=3D""><span style=3D"font-size:10.0pt;"> =C2=A0</span></p> =0A=
=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;color:=
blue;">namespace</span><span style=3D"=0Afont-size:10.0pt;"> NunitBackgroun=
dWorker</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"f=
ont-size:10.0pt;">{</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><spa=
n style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0 <span style=3D"color:blue;=
">public</span>=0A<span style=3D"color:blue;">class</span> <span style=3D"c=
olor:#2B91AF;">Background</span></span></p> =0A=0A<p class=3D"MsoNormal" st=
yle=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0 {</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span style=3D"color:blue;">priv=
ate</span> <span style=3D"color:#2B91AF;">BackgroundWorker</span>=0A_worker=
 =3D <span style=3D"color:blue;">null</span>;</span></p> =0A=0A<p class=3D"=
MsoNormal" style=3D""><span style=3D"font-size:10.0pt;"> =C2=A0</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span style=3D"color:blue;">publ=
ic</span> Background()</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><=
span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
 {</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-s=
ize:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=0A<span style=3D"color:#2B91AF;">Console</span>.WriteLine(<span styl=
e=3D"color:#A31515;">"ctor=0A"</span> + <span style=3D"color:#2B91AF;">Meth=
odInfo</span>.GetCurrentMethod().Name);</span></p> =0A=0A<p class=3D"MsoNor=
mal" style=3D""><span style=3D"font-size:10.0pt;"> =C2=A0</span></p> =0A=0A=
<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0AInitializeBa=
ckgoundWorker();</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span s=
tyle=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }</sp=
an></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10=
.0pt;"> =C2=A0</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span sty=
le=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span s=
tyle=3D"color:blue;">private</span> <span style=3D"color:blue;">void</span>=
=0AInitializeBackgoundWorker()</span></p> =0A=0A<p class=3D"MsoNormal" styl=
e=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 {</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=
=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=0A<span style=3D"color:blue;">int</span> dispatcherHash =3D=
 <span style=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thread.=
GetHashCode();</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span sty=
le=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:blue;">bool</span> isBackGround =
=3D <span style=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thre=
ad.IsBackground;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span s=
tyle=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:blue;">int</span> id =3D <span st=
yle=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thread.ManagedTh=
readId;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"f=
ont-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=0A<span style=3D"color:#2B91AF;">ApartmentState</span> thread_sta=
te =3D <span style=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher.T=
hread.GetApartmentState();</span></p> =0A=0A<p class=3D"MsoNormal" style=3D=
""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:#2B91AF;">Console</sp=
an>.WriteLine(<span style=3D"color:#2B91AF;">MethodInfo</span>.GetCurrentMe=
thod().Name);</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span styl=
e=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=0A<span style=3D"color:#2B91AF;">Console</span>.WriteLine(<=
span style=3D"color:#A31515;">"=C2=A0=C2=A0=C2=A0=C2=A0=0ADispatcherHash:{0=
}, IsBackground:{1}, Id:{2}, ThreadState:{3}"</span>,=0AdispatcherHash, isB=
ackGround, id, thread_state);</span></p> =0A=0A<p class=3D"MsoNormal" style=
=3D""><span style=3D"font-size:10.0pt;"> =C2=A0</span></p> =0A=0A<p class=
=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A_worker =3D <span sty=
le=3D"color:blue;">new</span> <span style=3D"color:#2B91AF;">BackgroundWork=
er</span>();</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=
=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=0A_worker.DoWork +=3D <span style=3D"color:blue;">new</span=
> <span style=3D"color:#2B91AF;">DoWorkEventHandler</span>(ProcessPhotosWor=
ker_DoWork);</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=
=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=0A_worker.RunWorkerCompleted +=3D <span style=3D"color:blue=
;">new</span> <span style=3D"color:#2B91AF;">RunWorkerCompletedEventHandler=
</span>(ProcessPhotosWorker_RunWorkerCompleted);</span></p> =0A=0A<p class=
=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A=C2=A0=C2=A0=C2=A0_worker.ProgressChang=
ed +=3D <span style=3D"color:blue;">new</span>=0A<span style=3D"color:#2B91=
AF;">ProgressChangedEventHandler</span>(ProcessPhotosWorker_ProgressChanged=
);</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-s=
ize:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=0A_worker.WorkerReportsProgress =3D <span style=3D"color:blue;">true=
</span>;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"=
font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;"> =
=C2=A0</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"fo=
nt-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span style=3D"=
color:blue;">void</span> ProcessPhotosWorker_ProgressChanged(<span style=3D=
"color:blue;">object</span> sender, <span style=3D"color:#2B91AF;">Progress=
ChangedEventArgs</span>=0Ae)</span></p> =0A=0A<p class=3D"MsoNormal" style=
=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 {</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=
=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=0A<span style=3D"color:blue;">int</span> dispatcherHash =3D=
 <span style=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thread.=
GetHashCode();</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span sty=
le=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:blue;">bool</span> isBackGround =
=3D <span style=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thre=
ad.IsBackground;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span s=
tyle=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:blue;">int</span> id =3D <span st=
yle=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thread.ManagedTh=
readId;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"f=
ont-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0<span style=3D"color:#2B91AF;">ApartmentState</span>=0Athread_s=
tate =3D <span style=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher=
.Thread.GetApartmentState();</span></p> =0A=0A<p class=3D"MsoNormal" style=
=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:#2B91AF;">Console<=
/span>.WriteLine(<span style=3D"color:#2B91AF;">MethodInfo</span>.GetCurren=
tMethod().Name=0A+ e.UserState.ToString());</span></p> =0A=0A<p class=3D"Ms=
oNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:#2B91A=
F;">Console</span>.WriteLine(<span style=3D"color:#A31515;">"=C2=A0=C2=A0=
=C2=A0=C2=A0=0ADispatcherHash:{0}, IsBackground:{1}, Id:{2}, ThreadState:{3=
}"</span>,=0AdispatcherHash, isBackGround, id, thread_state);</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }</span></p> =0A=0A<p class=3D"M=
soNormal" style=3D""><span style=3D"font-size:10.0pt;"> =C2=A0</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span style=3D"color:blue;">priv=
ate</span> <span style=3D"color:blue;">void</span>=0AProcessPhotosWorker_Do=
Work(<span style=3D"color:blue;">object</span> sender, <span style=3D"color=
:#2B91AF;">DoWorkEventArgs</span> e)</span></p> =0A=0A<p class=3D"MsoNormal=
" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 {</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span =
style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:blue;">int</span> dispatcherHa=
sh =3D <span style=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher.T=
hread.GetHashCode();</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><sp=
an style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:blue;">bool</span> isBackGr=
ound =3D <span style=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher=
.Thread.IsBackground;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><s=
pan style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:blue;">int</span> id =3D <s=
pan style=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thread.Man=
agedThreadId;</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span styl=
e=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=0A<span style=3D"color:#2B91AF;">ApartmentState</span> thre=
ad_state =3D <span style=3D"color:#2B91AF;">Dispatcher</span>.CurrentDispat=
cher.Thread.GetApartmentState();</span></p> =0A=0A<p class=3D"MsoNormal" st=
yle=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:#2B91AF;">Conso=
le</span>.WriteLine(<span style=3D"color:#2B91AF;">MethodInfo</span>.GetCur=
rentMethod().Name);</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><spa=
n style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"color:#2B91AF;">Console</span>.Write=
Line(<span style=3D"color:#A31515;">"=C2=A0=C2=A0=C2=A0=C2=A0=0ADispatcherH=
ash:{0}, IsBackground:{1}, Id:{2}, ThreadState:{3}"</span>,=0AdispatcherHas=
h, isBackGround, id, thread_state);</span></p> =0A=0A<p class=3D"MsoNormal"=
 style=3D""><span style=3D"font-size:10.0pt;"> =C2=A0</span></p> =0A=0A<p c=
lass=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A_worker.ReportP=
rogress(25, <span style=3D"color:#A31515;">"25%done"</span>);</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span =
style=3D"color:#2B91AF;">Thread</span>.Sleep(1000);</span></p> =0A=0A<p cla=
ss=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A_worker.ReportProg=
ress(50, <span style=3D"color:#A31515;">"50%done"</span>);</span></p> =0A=
=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span sty=
le=3D"color:#2B91AF;">Thread</span>.Sleep(1000);</span></p> =0A=0A<p class=
=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A_worker.ReportProgres=
s(75, <span style=3D"color:#A31515;">"75%done"</span>);</span></p> =0A=0A<p=
 class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"=
color:#2B91AF;">Thread</span>.Sleep(1000);</span></p> =0A=0A<p class=3D"Mso=
Normal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A_worker.ReportProgress(100,=
 <span style=3D"color:#A31515;">"100%done"</span>);</span></p> =0A=0A<p cla=
ss=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }</span></p> =0A=0A<p class=3D"MsoNormal" st=
yle=3D""><span style=3D"font-size:10.0pt;"> =C2=A0</span></p> =0A=0A<p clas=
s=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span style=3D"color:blue;">void</span> Proc=
essPhotosWorker_RunWorkerCompleted(<span style=3D"color:blue;">object</span=
> sender, <span style=3D"color:#2B91AF;">RunWorkerCompletedEventArgs</span>=
=0Ae)</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"fon=
t-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {</span></p> =0A=
=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span sty=
le=3D"color:blue;">int</span> dispatcherHash =3D <span style=3D"color:#2B91=
AF;">Dispatcher</span>.CurrentDispatcher.Thread.GetHashCode();</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span =
style=3D"color:blue;">bool</span> isBackGround =3D <span style=3D"color:#2B=
91AF;">Dispatcher</span>.CurrentDispatcher.Thread.IsBackground;</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span =
style=3D"color:blue;">int</span> id =3D <span style=3D"color:#2B91AF;">Disp=
atcher</span>.CurrentDispatcher.Thread.ManagedThreadId;</span></p> =0A=0A<p=
 class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span style=3D"=
color:#2B91AF;">ApartmentState</span> thread_state =3D <span style=3D"color=
:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thread.GetApartmentState();<=
/span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size=
:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=0A<span style=3D"color:#2B91AF;">Console</span>.WriteLine(<span style=
=3D"color:#2B91AF;">MethodInfo</span>.GetCurrentMethod().Name);</span></p> =
=0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span =
style=3D"color:#2B91AF;">Console</span>.WriteLine(<span style=3D"color:#A31=
515;">"=C2=A0=C2=A0=C2=A0=C2=A0=0ADispatcherHash:{0}, IsBackground:{1}, Id:=
{2}, ThreadState:{3}"</span>,=0AdispatcherHash, isBackGround, id, thread_st=
ate);</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"fon=
t-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }</span></p> =0A=
=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;"> =C2=
=A0</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-=
size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span style=3D"col=
or:blue;">public</span> <span style=3D"color:blue;">void</span>=0ARunBackgr=
oundWorker()</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=
=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {</span><=
/p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt=
;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<sp=
an style=3D"color:blue;">int</span> dispatcherHash =3D <span style=3D"color=
:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thread.GetHashCode();</span>=
</p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0p=
t;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<s=
pan style=3D"color:blue;">bool</span> isBackGround =3D <span style=3D"color=
:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thread.IsBackground;</span><=
/p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt=
;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<sp=
an style=3D"color:blue;">int</span> id =3D <span style=3D"color:#2B91AF;">D=
ispatcher</span>.CurrentDispatcher.Thread.ManagedThreadId;</span></p> =0A=
=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<span sty=
le=3D"color:#2B91AF;">ApartmentState</span> thread_state =3D <span style=3D=
"color:#2B91AF;">Dispatcher</span>.CurrentDispatcher.Thread.GetApartmentSta=
te();</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"fon=
t-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=0A<span style=3D"color:#2B91AF;">Console</span>.WriteLine(<span s=
tyle=3D"color:#2B91AF;">MethodInfo</span>.GetCurrentMethod().Name);</span><=
/p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt=
;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A<sp=
an style=3D"color:#2B91AF;">Console</span>.WriteLine(<span style=3D"color:#=
A31515;">"=C2=A0=C2=A0=C2=A0=C2=A0=0ADispatcherHash:{0}, IsBackground:{1}, =
Id:{2}, ThreadState:{3}"</span>,=0AdispatcherHash, isBackGround, id, thread=
_state);</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><span style=3D"=
font-size:10.0pt;"> =C2=A0</span></p> =0A=0A<p class=3D"MsoNormal" style=3D=
""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=0A_worker.RunWorkerAsync(<span style=
=3D"color:#A31515;">"TestData"</span>);</span></p> =0A=0A<p class=3D"MsoNor=
mal" style=3D""><span style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 }</span></p> =0A=0A<p class=3D"MsoNormal" style=3D""><sp=
an style=3D"font-size:10.0pt;">=C2=A0=C2=A0=C2=A0 }</span></p> =0A=0A<p cla=
ss=3D"MsoNormal" style=3D""><span style=3D"font-size:10.0pt;">}</span></p> =
=0A=0A<p class=3D"MsoNormal"><span lang=3D"EN-AU" style=3D""> =C2=A0</span>=
</p></div><div style=3D""></div></div><br>=0A=0A=0A=0A=0A      </div></div>=
<div style=3D"position:fixed"></div></div><br>=0A=0A=0A=0A=0A      </body><=
/html>
--0-1227559037-1222254753=:50408--


--===============1339275186360869297==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
--===============1339275186360869297==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users

--===============1339275186360869297==--