本文整理汇总了C#中System.Threading.Thread.TrySetApartmentState方法的典型用法代码示例。如果您正苦于以下问题:C# Thread.TrySetApartmentState方法的具体用法?C# Thread.TrySetApartmentState怎么用?C# Thread.TrySetApartmentState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Thread
的用法示例。
在下文中一共展示了Thread.TrySetApartmentState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: myScreenshot
private static void myScreenshot()
{
var thread = new Thread(ThreadStart);
// allow UI with ApartmentState.STA though [STAThread] above should give that to you
thread.TrySetApartmentState(ApartmentState.STA);
thread.Start();
}
示例2: Run
public void Run()
{
//Start thread for UI
var thread = new Thread(ThreadStart);
thread.TrySetApartmentState(ApartmentState.STA);
thread.Start();
CreatePlayers();
//Sets players in current game
GenerateCurrPlayers();
//врътка players
GenerateCyclePlayers();
dealer.FillDeck(database, cardFactory);
dealer.Shuffle(database.Deck);
dealer.DealCards(database.Deck, database.HumanPlayers, database.BotPlayers, database.TableCards);
//Sets players power depending on their cards combinations
SetPlayersPower();
AddBlindsToPot();
}
示例3: Main
static void Main()
{
// Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
//try
//{
Game game = new Game();
GameForm gf;
gf = new GameForm(game);
Thread t = new Thread(new ParameterizedThreadStart(game.Start));
t.Name = "GameLoop";
t.IsBackground = true;
t.TrySetApartmentState(ApartmentState.STA);
t.Start(gf);
//Thread tt = new Thread(new ThreadStart(gf.Show2));
//tt.Start();
gf.Init();
//}
//catch (Exception e) { MessageBox.Show(e.Message + e.InnerException + e.Source + e.StackTrace); }
//if (t.ThreadState == ThreadState.Running)
// t.Abort();
//Application.Run(new GameForm());
}
示例4: VisualizatorDomainAppl
protected VisualizatorDomainAppl()
{
_thread = new Thread(WorkThread);
if (!_thread.TrySetApartmentState(ApartmentState.STA))
throw new Exception("Не удалось установить STA ApartmentState");
_main = new InvisibleMainForm(this);
}
示例5: NetStateController
public NetStateController()
{
recv = new NetStreamMultiReceiver(RTSConstants.MC_ADDR, RTSConstants.MC_GAME_PORT_MIN);
tNet = new Thread(NetThread);
tNet.Priority = ThreadPriority.BelowNormal;
tNet.TrySetApartmentState(ApartmentState.MTA);
tNet.IsBackground = true;
}
示例6: MessageLoop
public MessageLoop()
{
thread = new Thread(threadLoop);
thread.TrySetApartmentState(ApartmentState.STA);
threadStarted = new TaskCompletionSource<bool>();
thread.Start();
threadStarted.Task.Wait();
}
示例7: button3_Click
// create package
private void button3_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedItem != null)
{
StartProcessing();
thr = new Thread(new ParameterizedThreadStart(ProcessPackage));
thr.TrySetApartmentState(ApartmentState.STA); // this fixes saveFileDialog exception
thr.Start(comboBox1.SelectedItem);
}
}
示例8: clientListUpdated
public void clientListUpdated(long count)
{
if (controller == null)
controller = ChatController.getController();
Console.WriteLine("* New client list is ready, event is: " + count);
Thread t = new Thread(() => controller.updateClientList(count));
t.TrySetApartmentState(ApartmentState.STA);
t.Start();
}
示例9: Plotter
public Plotter(string title, params Series[] s)
{
//new Plotter("Train", new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"))
Title = title;
Series = s;
InitializeComponent();
var thread = new Thread(() => Application.Run(this));
thread.TrySetApartmentState(ApartmentState.STA);
thread.Start();
}
示例10: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var thread = new Thread(ThreadStart);
// allow UI with ApartmentState.STA though [STAThread] above should give that to you
thread.TrySetApartmentState(ApartmentState.STA);
thread.Start();
Application.Run(new GateIn());
}
示例11: StartListenerThread
private void StartListenerThread()
{
Trace.WriteLine("++WorkerRole.StartListenerThread", "Information");
_listenerThread = null;
_listenerThread = new Thread(TCPListener.TcpListenerProcess);
_listenerThread.TrySetApartmentState(ApartmentState.STA);
_listenerThread.Name = "Server TCP Listener";
_listenerThread.Start();
Trace.WriteLine("--WorkerRole.StartListenerThread", "Information");
}
示例12: Start
/// <summary>
/// Open the 3D visualization in a exclusive thread in order to it do not create
/// a conflict with the application thread
/// </summary>
public static void Start()
{
// If there is already a thread, kill it
if (_thread != null && _thread.IsAlive)
{
_thread.Abort();
}
// Start a new thread calling startMethod method
_thread = new Thread(StartMethod);
_thread.TrySetApartmentState(ApartmentState.MTA);
_thread.Start();
IsActive = true;
}
示例13: KeepConntion
/// <summary>
/// 通过线程每隔一点时间刷数据库,保持连接
/// </summary>
public static void KeepConntion()
{
_thread = new Thread(LoopDual);
_thread.Name = "KeepOracleConnection";
_thread.IsBackground = true;
// 设置线程状态为单线程
try
{
_thread.TrySetApartmentState(ApartmentState.STA);
}
catch (Exception ex)
{
Logging.Write("KeepConntion 启动失败,线程设置出现错误,原因是:" + ex.ToString());
return;
}
_thread.Start();
}
示例14: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
PXCMSession session = null;
pxcmStatus sts = PXCMSession.CreateInstance(out session);
if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR)
{
var thread = new Thread(ThreadStart);
// allow UI with ApartmentState.STA though [STAThread] above should give that to you
thread.TrySetApartmentState(ApartmentState.STA);
thread.Start();
Application.Run(new MainForm(session));
session.Dispose();
}
}
示例15: Loop
//constructor
public Loop(Main window, int targetUps, Boolean fpsLock, int maxFps)
{
//Console.WriteLine(window.GPanel.Visible);
//stelt alle variablen in
this.window = window;
//window.GPanel.
window.Paint += this.render;
this.targetUps = targetUps;
this.fpsLock = fpsLock;
this.maxFps = maxFps;
//intalizeerd het spel
game = new Game(this);
//initalizeerd de gameloop thraed en start hem op de methode init();
t = new Thread(init);
t.Priority = ThreadPriority.Highest;
t.TrySetApartmentState(ApartmentState.MTA);
t.Start();
}