TrySetApartmentState() public method

public TrySetApartmentState ( System state ) : bool
state System
return bool
コード例 #1
0
        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();
        }
コード例 #2
0
 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();
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: DarkLotus/TD
        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
0
 protected VisualizatorDomainAppl()
 {
     _thread = new Thread(WorkThread);
     if (!_thread.TrySetApartmentState(ApartmentState.STA))
         throw new Exception("Не удалось установить STA ApartmentState");
     _main = new InvisibleMainForm(this);
 }
コード例 #5
0
 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
0
ファイル: Program.cs プロジェクト: CyAScott/MessageLoop
        public MessageLoop()
        {
            thread = new Thread(threadLoop);
            thread.TrySetApartmentState(ApartmentState.STA);
            threadStarted = new TaskCompletionSource<bool>();

            thread.Start();

            threadStarted.Task.Wait();
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: plamikcho/easyresx
 // 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
0
        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
0
ファイル: Plotter.cs プロジェクト: benketriel/sknn
        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
0
ファイル: Program.cs プロジェクト: christandrian/sampleApp
        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
0
ファイル: WorkerRole.cs プロジェクト: jonathanyeung/ozwego
        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
0
ファイル: Simulation3D.cs プロジェクト: intruder01/20150105
		/// <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
0
ファイル: OraData.cs プロジェクト: civicacid/myevo
 /// <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
0
        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
0
ファイル: Loop.cs プロジェクト: michieljanssen/ICTSE1a4KBS1
        //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();
        }
コード例 #16
0
ファイル: StressTestHandler.cs プロジェクト: rocketeerbkw/DNA
        public void RunTest()
        {
            GetPreviousResults();
            var directoryInfo = new DirectoryInfo(WorkingDirectory + _outputFolder);
            directoryInfo.Create();

            var wcatServer = new WcatServer(WorkingDirectory, _testName, WarmUpTime, Duration, CoolDownTime, _outputFolder, _server, _serverName);
            var wcatServerThread = new Thread(wcatServer.Start);
            wcatServerThread.TrySetApartmentState(ApartmentState.MTA);
            var wcatClient = new WcatClient(WorkingDirectory);
            var wcatClientThread = new Thread(wcatClient.Start);
            wcatClientThread.TrySetApartmentState(ApartmentState.MTA);

            //wcatServerThread.IsBackground = true;
            //wcatClientThread.IsBackground = true;
            wcatServerThread.Start();
            Thread.Sleep(2000);//wait for server to start
            wcatClientThread.Start();
            Thread.Sleep(2000);//wait for client to start
            while (wcatServerThread.ThreadState != ThreadState.Stopped)
            {
                //Thread.Sleep(1000);
            }

            Assert.IsTrue(File.Exists(WorkingDirectory + _outputFolder + "\\log.log"));
            LoggingHelper.WriteFileSection("RUN LOG FILE", WorkingDirectory + _outputFolder + "\\log.log");

            Assert.IsTrue(File.Exists(WorkingDirectory + _outputFolder + "\\log.xml"));
            LoggingHelper.WriteFileSection("RUN XML LOG FILE", WorkingDirectory + _outputFolder + "\\log.xml");
            _xmlResults = new XmlDocument();
            _xmlResults.Load(WorkingDirectory + _outputFolder + "\\log.xml");

            Assert.IsTrue(File.Exists(WorkingDirectory + _outputFolder + "\\log.prf"));
            LoggingHelper.WriteFileSection("RUN PERFMON LOG FILE", WorkingDirectory + _outputFolder + "\\log.prf");

            if (_prevXmlResults == null)
            {
                Assert.Inconclusive("Unable to find previous run");
            }
        }
コード例 #17
0
        public static void Export(DataTable data, string name)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Title = "Export " + name + " data to csv";
            dialog.Filter = "csv files (*.csv)|*.csv";
            dialog.AddExtension = true;
            dialog.DefaultExt = ".csv";
            dialog.OverwritePrompt = true;
            dialog.InitialDirectory = UserAccount.Settings.CSVExportDir;
            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                _filename = dialog.FileName;
                CSVExport expObj = new CSVExport();
                Thread t1 = new Thread(new ParameterizedThreadStart(expObj.DoExport));
                t1.TrySetApartmentState(ApartmentState.STA);
                ProgressDialog prgDialog = new ProgressDialog("Building " + name + " CSV file...", expObj);
                t1.Start(data);
                prgDialog.ShowDialog();
            }
        }
コード例 #18
0
ファイル: SafeThread.cs プロジェクト: elyor0529/MonetDB
        /// <summary>
        /// starts thread execution
        /// </summary>
        public void Start()
        {
            ThreadObject = new Thread(new ThreadStart(StartTarget))
            {
                Name = this.Name
            };

            if (_aptState != null)
            {
                ThreadObject.TrySetApartmentState((ApartmentState) _aptState);
            }

            ThreadObject.Start();
        }
コード例 #19
0
ファイル: SpyWOW.cs プロジェクト: civicacid/myevo
 public static void startScanDB()
 {
     if (_thread == null || !_thread.IsAlive)
     {
         _thread = new Thread(GoGo);
         _thread.Name = "Schduler";
         _thread.IsBackground = true;
         // 设置线程状态为单线程
         try
         {
             _thread.TrySetApartmentState(ApartmentState.STA);
         }
         catch (Exception ex)
         {
             Logging.Write("启动失败,线程设置出现错误,原因是:" + ex.ToString());
             return;
         }
         _thread.Start();
         Logging.Write("计划开始运行。。。。。");
         SpyDB.WriteLog("计划任务", "开始运行");
     }
 }
コード例 #20
0
ファイル: SpyWOW.cs プロジェクト: civicacid/myevo
        public static void StartFB()
        {
            BarMapper.MapBars();
            KeyHelper.LoadKeys();

            if (_Thread == null || !_Thread.IsAlive)
            {
                _Thread = new Thread(gogo);
                _Thread.Name = "FB";
                _Thread.IsBackground = true;
                // 设置线程状态为单线程
                try
                {
                    _Thread.TrySetApartmentState(ApartmentState.STA);
                }
                catch (Exception ex)
                {
                    Logging.Write("启动失败,线程设置出现错误,原因是:" + ex.ToString());
                    return;
                }
                _Thread.Start();
                Logging.Write("开始了。。。。。");
            }
        }
コード例 #21
0
ファイル: SpyWOW.cs プロジェクト: civicacid/myevo
 public static void start()
 {
     if (_AutoLogin == null || !_AutoLogin.IsAlive)
     {
         _AutoLogin = new Thread(gogo);
         _AutoLogin.Name = "AutoLoginWOW";
         _AutoLogin.IsBackground = true;
         // 设置线程状态为单线程
         try
         {
             _AutoLogin.TrySetApartmentState(ApartmentState.STA);
         }
         catch (Exception ex)
         {
             Logging.Write("启动失败,线程设置出现错误,原因是:" + ex.ToString());
             return;
         }
         _AutoLogin.Start();
         Logging.Write("AutoLoginWOW开始了。。。。。");
     }
 }
コード例 #22
0
ファイル: SpyWOW.cs プロジェクト: civicacid/myevo
 public static void start()
 {
     if (Items == null || Items.Columns.Count == 0)
     {
         Logging.Write("没有设置拍卖列表");
         return;
     }
     if (_thread == null || !_thread.IsAlive)
     {
         _thread = new Thread(gogo);
         _thread.Name = "AutoAH";
         _thread.IsBackground = true;
         // 设置线程状态为单线程
         try
         {
             _thread.TrySetApartmentState(ApartmentState.STA);
         }
         catch (Exception ex)
         {
             Logging.Write("启动失败,线程设置出现错误,原因是:" + ex.ToString());
             return;
         }
         _thread.Start();
         Logging.Write("自动拍卖开始了。。。。。");
     }
 }
コード例 #23
0
ファイル: SpyWOW.cs プロジェクト: civicacid/myevo
        public static void start()
        {
            if (_thread == null || !_thread.IsAlive)
            {
                _thread = new Thread(GoGo);
                _thread.Name = "分解矿";
                _thread.IsBackground = true;
                // 设置线程状态为单线程
                try
                {
                    _thread.TrySetApartmentState(ApartmentState.STA);
                }
                catch (Exception ex)
                {
                    Logging.Write("启动失败,线程设置出现错误,原因是:" + ex.ToString());
                    RUNNING = false;
                    return;
                }
                _thread.Start();
                Logging.Write("分解矿 开始了。。。。。");

            }
        }
コード例 #24
0
ファイル: ThreadTest.cs プロジェクト: REALTOBIZ/mono
		public void TestTrySetApartmentStateRunning ()
		{
			Thread t1 = new Thread (new ThreadStart (Start));
			t1.SetApartmentState (ApartmentState.STA);
			Assert.AreEqual (ApartmentState.STA, t1.ApartmentState, "#1");

			t1.Start ();

			try {
				t1.TrySetApartmentState (ApartmentState.STA);
				Assert.Fail ("#2");
			} catch (ThreadStateException) {
			}

			t1.Join ();
		}
コード例 #25
0
ファイル: ThreadTest.cs プロジェクト: REALTOBIZ/mono
		public void TestTrySetApartmentState ()
		{
			Thread t1 = new Thread (new ThreadStart (Start));
			t1.SetApartmentState (ApartmentState.STA);
			Assert.AreEqual (ApartmentState.STA, t1.ApartmentState, "#1");

			bool result = t1.TrySetApartmentState (ApartmentState.MTA);
			Assert.IsFalse (result, "#2");

			result = t1.TrySetApartmentState (ApartmentState.STA);
			Assert.IsTrue (result, "#3");
		}
コード例 #26
0
 public bool TrySetApartmentState(ApartmentState state)
 {
     return(_Thread.TrySetApartmentState(state));
 }
コード例 #27
0
ファイル: ThisAddIn.cs プロジェクト: nkravch/SALMA-2.0
        /// <summary>
        /// Normal text
        /// </summary>
        /// <param name="text"></param>
        private void NormalText(string text)
        {
            if (String.IsNullOrWhiteSpace(text))
            {
                return;
            }

            Object styleTitle = WdBuiltinStyle.wdStyleNormalObject;
            Object styleTitle2 = WdBuiltinStyle.wdStyleHtmlNormal;
            var doc = Application.ActiveDocument;
            var pt = OfficeHelper.CreateParagraphRange(ref doc);
            pt.Text = text;
            pt.set_Style(ref styleTitle2);

            var thread = new Thread(SetClipboard);
            if (thread.TrySetApartmentState(ApartmentState.STA))
            {
                thread.Start(text);
                thread.Join();
            }

            try
            {
                object objDataTypeMetafile = WdPasteDataType.wdPasteHTML;
                pt.PasteSpecial(DataType: objDataTypeMetafile);
                if (Application.ActiveDocument.InlineShapes.Count > 0)
                {
                    var page = Application.ActiveDocument.PageSetup;
                    float calculatedWidth = page.PageWidth - (page.LeftMargin + page.RightMargin);

                    foreach (InlineShape shape in Application.ActiveDocument.InlineShapes)
                    {
                        shape.LockAspectRatio = MsoTriState.msoTrue;

                        if (shape.Width <= calculatedWidth) continue;

                        shape.Width = calculatedWidth;
                    }
                }
            }
            catch (Exception)
            {
            }

            Application.ActiveDocument.Content.InsertParagraphAfter();
        }
コード例 #28
0
 private void _createUpdateClientThread()
 {
     Thread t = new Thread(informClientsListChanged);
     t.TrySetApartmentState(ApartmentState.STA);
     t.Start();
 }
コード例 #29
0
ファイル: VideoCaptureDevice.cs プロジェクト: tdhieu/iSpy
        /// <summary>
        /// Start video source.
        /// </summary>
        /// 
        /// <remarks>Starts video source and return execution to caller. Video source
        /// object creates background thread and notifies about new frames with the
        /// help of <see cref="NewFrame"/> event.</remarks>
        /// 
        public void Start( )
        {
            if ( !IsRunning )
            {
                // check source
                if ( string.IsNullOrEmpty( _deviceMoniker ) )
                    throw new ArgumentException( "Video source is not specified." );

                _framesReceived = 0;
                _bytesReceived = 0;
                _isCrossbarAvailable = null;
                _needToSetVideoInput = true;

                // create events
                _stopEvent = new ManualResetEvent( false );

                lock ( _sync )
                {
                    // create and start new thread
                    _thread = new Thread( WorkerThread ) {Name = _deviceMoniker, IsBackground = true};
                    _thread.TrySetApartmentState(ApartmentState.STA);
                    _thread.Start( );
                }
            }
        }
コード例 #30
0
ファイル: MapiMailMessage.cs プロジェクト: x893/WDS
 public void ShowDialog()
 {
     Thread thread = new Thread(new ThreadStart(this._ShowMail)) {
         Name = "Mail msg thread",
         IsBackground = true
     };
     thread.TrySetApartmentState(ApartmentState.STA);
     thread.Start();
     this._manualResetEvent.WaitOne();
     this._manualResetEvent.Reset();
 }
コード例 #31
0
ファイル: Compiler.cs プロジェクト: daszat/zetbox
        private void CompileCodeOnStaThread(string workingPath)
        {
            Exception failed = null;
            bool success = false;
            var staThread = new Thread(() => { try { success = CompileCode(workingPath); } catch (Exception ex) { failed = ex; } });
            if (staThread.TrySetApartmentState(ApartmentState.STA))
            {
                _log.Info("Successfully set STA on compile thread");
            }
            else
            {
                _log.Warn("STA not set on compile thread");
            }
            staThread.Name = "Compile";
            staThread.Start();
            staThread.Join();

            if (failed != null)
            {
                throw new ApplicationException("Compilation failed", failed);
            }

            if (!success)
            {
                throw new ApplicationException("Compilation failed");
            }
        }