- threadsafeui.zip
- ThreadSafeUI
- AOPAttributes.sln
- AOPAttributes.suo
- Castle.Core.dll
- Castle.DynamicProxy2.dll
- TeamAgile.SimpleInterception
- TeamAgile.ThreadSafeUI
- Test
- ThreadSafeUI
|
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using NUnit.Framework;
using Osherove.SimpleInterception;
using System.Diagnostics;
using System.Windows.Forms;
namespace AOP.UnitTest
{
[TestFixture]
public class AOPTest
{
bool InvokeRequired = false;
public void TestSetup()
{
//init var so we know other tests aren't affecting it
InvokeRequired = false;
Assert.IsFalse(InvokeRequired);
}
void form_InvokeRequiredEvent(bool isInvokeRequired)
{
//record whether or not the invoke was required
InvokeRequired = isInvokeRequired;
}
[Test]
public void TestNormalFormCrossThreadedProblem() //this simulates what happens on a winform app when functionality is called in a different thread
{
TestSetup();
//create and launch form which is set to do a cross threaded operation for testing our AOP method of easily getting around the cross threaded UI issue
AOP_TestForm form = new AOP_TestForm(AOP_TestForm.LoadTypeEnum.Bad);
form.InvokeRequiredEvent += new AOP_TestForm.InvokeRequiredEventType(form_InvokeRequiredEvent);
Application.Run(form); //run the app, message pump, all that goodness
//this reproduces the original problem, invoke is required
Assert.IsTrue(InvokeRequired);
}
[Test]
public void TestFormCrossThreadedProblemFixManual() //this simulates what happens on a winform app when functionality is called in a different thread
{
TestSetup();
//create and launch form which is set to do a cross threaded operation for testing our AOP method of easily getting around the cross threaded UI issue
AOP_TestForm form = new AOP_TestForm(AOP_TestForm.LoadTypeEnum.GoodManual);
form.InvokeRequiredEvent += new AOP_TestForm.InvokeRequiredEventType(form_InvokeRequiredEvent);
Application.Run(form); //run the app, message pump, all that goodness
//the above should fix it, invoke should not be required
Assert.IsFalse(InvokeRequired);
}
[Test]
public void TestFormCrossThreadedProblemFixAOP() //this simulates what happens on a winform app when functionality is called in a different thread
{
TestSetup();
//create and launch form which is set to do a cross threaded operation for testing our AOP method of easily getting around the cross threaded UI issue
AOP_TestForm form = AOPFactory.Create<AOP_TestForm>();
form.InvokeRequiredEvent += new AOP_TestForm.InvokeRequiredEventType(form_InvokeRequiredEvent);
Application.Run(form); //run the app, message pump, all that goodness
//the above should fix it, invoke should not be required
Assert.IsFalse(InvokeRequired);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
I've been a software developer since 1996 and have enjoyed C# since 2003. I have a Bachelor's degree in Computer Science and for some reason, a Master's degree in Business Administration. I currently do software development contracting/consulting.