我很想知道 C# .net 中何时使用 STA/MTA?
using (ManualResetEventSlim mre = new ManualResetEventSlim(false))
{
Thread _STAThread = new Thread(new ThreadStart(() =>
{
globalComObject = new ComClass();
mre.Set();
try
{
Thread.CurrentThread.Join();
}
catch (ThreadAbortException)
{ }
}));
_STAThread.SetApartmentState(ApartmentState.STA);
_STAThread.IsBackground = true;
_STAThread.Start();
mre.Wait();
}
Run Code Online (Sandbox Code Playgroud) //overloading operator ==
class Point
{
private int m_X,int m_Y;
public static operator == (Point p1 ,Point p2)
{
if(object.ReferenceEquals(p1,p2)
return true;
if((object)(p1) == null) || ((object)(p2) ==null)
return false;
return( (p1.x == p2.x) && (p1.x == p2.x));
}
//overloading the != operator
}
Run Code Online (Sandbox Code Playgroud)