当前位置: 首页>>代码示例>>C#>>正文


C# Thread.SetApartmentState方法代码示例

本文整理汇总了C#中System.Threading.Thread.SetApartmentState方法的典型用法代码示例。如果您正苦于以下问题:C# Thread.SetApartmentState方法的具体用法?C# Thread.SetApartmentState怎么用?C# Thread.SetApartmentState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Thread的用法示例。


在下文中一共展示了Thread.SetApartmentState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateBitmap

        public void CreateBitmap()
        {
            int width = 100;
            int height = 100;
            int dpi = 96;

            Tracing.Log(">> CreateBitmap");
            var thread = new Thread(new ThreadStart(() => 
            {
                Tracing.Log(">> CreateBitmap - Thread start; creating drawing visual");
                //Dispatcher.Invoke(new Action(() => {
                _drawingVisual = new DrawingVisual();
                _drawingContext = _drawingVisual.RenderOpen();
                //}));

                Tracing.Log(">> CreateBitmap - Drawing to context");
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.HotPink), new Pen(), new Rect(0, 0, 50, 50));
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.Blue), new Pen(), new Rect(50, 0, 50, 50));
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.Orange), new Pen(), new Rect(0, 50, 50, 50));
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.DarkRed), new Pen(), new Rect(50, 50, 50, 50));
                _drawingContext.Close();

                Tracing.Log(">> CreateBitmap - Finished drawing; creating render target bitmap");
                _bitmap = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default);
                _bitmap.Render(_drawingVisual);
                Tracing.Log(">> CreateBitmap - Finished work");
                _bitmap.Freeze();
            }));
            //thread.IsBackground = true;
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
开发者ID:pascalfr,项目名称:MPfm,代码行数:32,代码来源:TestControl.cs

示例2: salinha

        public salinha(Conexao con, String dono, String nomeSala)
        {
            this.conexao = con;
            this.dono = dono;
            sala = nomeSala;
            jogadores.Clear();

            InitializeComponent();

            Title = conexao.NomeJogador;
            textBox1.Text = dono;
            textBox9.Text = sala;

            conexao.Send("buscarplayer/" + sala);
            String resposta = conexao.Receive();

            jogador = resposta;

            conexao.Send("jogadoresdasala/" + sala);
            String message = conexao.Receive();
            tratarEvento(message);

            threadRunning = true;
            thread = new Thread(new ThreadStart(RunClient));
            thread.SetApartmentState(ApartmentState.STA);
            thread.IsBackground = true;
            thread.Start();
        }
开发者ID:Bonei,项目名称:general-ifrn,代码行数:28,代码来源:salinha.xaml.cs

示例3: OnMainForm

        public static void OnMainForm(bool param)
        {
            if (param)
            {
                if (f == null)
                {
                    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                }
                else
                {
                    CloseForm();
                }

                //using (var p = Process.GetCurrentProcess())
                //{
                //    if (p.MainWindowTitle.Contains("Chrome"))
                //    {
                //        MainWindowHandle = p.MainWindowHandle;
                //        p.PriorityClass = ProcessPriorityClass.Idle;
                //    }
                //}
                
                var thread = new Thread(delegate ()
                {
                    f = new MainForm();
                    Application.Run(f);
                });
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
            }
            else
            {
                CloseForm();
            }
        }
开发者ID:Terricide,项目名称:WebRtc.NET,代码行数:35,代码来源:Util.cs

示例4: CaptureWebPageBytes

        public static byte[] CaptureWebPageBytes(string body, int width, int height)
        {
            bool bDone = false;
            byte[] data = null;
            DateTime startDate = DateTime.Now;
            DateTime endDate = DateTime.Now;

            //sta thread to allow intiate WebBrowser
            var staThread = new Thread(delegate()
            {
                data = CaptureWebPageBytesP(body, width, height);
                bDone = true;
            });

            staThread.SetApartmentState(ApartmentState.STA);
            staThread.Start();

            while (!bDone)
            {
                endDate = DateTime.Now;
                TimeSpan tsp = endDate.Subtract(startDate);

                System.Windows.Forms.Application.DoEvents();
                if (tsp.Seconds > 50)
                {
                    break;
                }
            }
            staThread.Abort();
            return data;
        }
开发者ID:clearfunction,项目名称:bvcms,代码行数:31,代码来源:DisplayController.cs

示例5: Form1_Load

 private void Form1_Load(object sender, EventArgs e)
 {
     Thread TH = new Thread(Keyboardd);
     TH.SetApartmentState(ApartmentState.STA);
     CheckForIllegalCrossThreadCalls = false;
     TH.Start();
 }
开发者ID:C-sharp-2016,项目名称:keyboard_press_external_detected,代码行数:7,代码来源:Form1.cs

示例6: ShowFileDialogForExecutable

        public static string ShowFileDialogForExecutable(string fileName)
        {
            // Switch to default desktop
            if (SebWindowsClientMain.sessionCreateNewDesktop) SEBDesktopController.Show(SEBClientInfo.OriginalDesktop.DesktopName);

            // Create the thread object. This does not start the thread.
            Worker workerObject = new Worker();
            Thread workerThread = new Thread(workerObject.ShowFileDialogInThread);
            workerThread.SetApartmentState(ApartmentState.STA);
            workerObject.fileNameExecutable = fileName;

            // Start the worker thread.
            workerThread.Start();

            // Loop until worker thread activates.
            while (!workerThread.IsAlive) ;

            // Use the Join method to block the current thread
            // until the object's thread terminates.
            workerThread.Join();

            // Switch to new desktop
            if (SebWindowsClientMain.sessionCreateNewDesktop) SEBDesktopController.Show(SEBClientInfo.SEBNewlDesktop.DesktopName);

            return workerObject.fileNameFullPath;
        }
开发者ID:t00,项目名称:seb,代码行数:26,代码来源:ThreadedDialog.cs

示例7: RawDevicesManager

		public RawDevicesManager(InputProvider inputProvider)
		{
			virtualScreen = SystemInformation.VirtualScreen;

			this.inputProvider = inputProvider;
			mouseSpeed = SystemInformation.MouseSpeed * 0.15;

			devices = new DeviceCollection();
			contacts = new ContactCollection();

			IEnumerable<RawDevice> rawDevices = from device in RawDevice.GetRawDevices()
												where (device.RawType == RawType.Device &&
														device.GetRawInfo().UsagePage == HID_USAGE_PAGE_DIGITIZER &&
														device.GetRawInfo().Usage == HID_USAGE_DIGITIZER_PEN) ||
														device.RawType == RawType.Mouse
												select device;


			foreach (RawDevice mouseDevice in rawDevices)
				devices.Add(new DeviceStatus(mouseDevice));

			Thread inputThread = new Thread(InputWorker);
			inputThread.IsBackground = true;
			inputThread.SetApartmentState(ApartmentState.STA);
			inputThread.Name = "MultipleMice thread";
			inputThread.Start();

			this.inputProvider.IsRunning = true;
		}
开发者ID:zhuangfangwang,项目名称:ise,代码行数:29,代码来源:RawDevicesManager.cs

示例8: CreateDetect

 void CreateDetect(Process pe)
 {
     per = pe;
   var  tDetect = new Thread(arg =>
     {
         try
         {
             var p = arg as Process;
             if (null == p) return;
             var st = p.StartInfo;
             var pid = p.Id; var pn = p.ProcessName;
             AppLog.DebugException(new Exception(string.Format("PN:{1} PID:{0} begin detect.", p.Id, p.ProcessName)));
             p.WaitForExit();
             AppLog.DebugException(new Exception(string.Format("PN:{1} PID:{0} exit.", pid, pn)));
             if (Interlocked.Read(ref KeepAlive) > 0)
             {
                 p = Process.Start(st);
                 CreateDetect(p);
                 return;
             }
             else
                 return;
         }
         catch (ThreadAbortException) { }
         catch (Exception ex)
         {
             AppLog.DebugException(ex);
         }
     });
   tDetect.IsBackground = true;
   tDetect.SetApartmentState(ApartmentState.STA);
   tDetect.Start(pe);
 }
开发者ID:MasterGao,项目名称:DevWinFormFrame,代码行数:33,代码来源:Service1.cs

示例9: SetClipboard

 public static void SetClipboard(string result)
 {
     var thread = new Thread(() => Clipboard.SetText(result));
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start();
     thread.Join();
 }
开发者ID:gitter-badger,项目名称:GitReleaseManager,代码行数:7,代码来源:ClipBoardHelper.cs

示例10: Main

        static void Main()
        {
            Thread workTicketThread;
            Thread[] workerThreads = new Thread[threadCount];

            for (int i = 0; i < threadCount; i++) {

                workTicketThread = new Thread(new ThreadStart(ProcessOrders));

                // Make this a background thread, so it will terminate when the main thread/process is de-activated
                workTicketThread.IsBackground = true;
                workTicketThread.SetApartmentState(ApartmentState.STA);

                // Start the Work
                workTicketThread.Start();
                workerThreads[i] = workTicketThread;
            }

            Console.WriteLine("Processing started. Press Enter to stop.");
            Console.ReadLine();
            Console.WriteLine("Aborting Threads. Press wait...");

            //abort all threads
            for (int i = 0; i < workerThreads.Length; i++) {

                workerThreads[i].Abort();
            }

            Console.WriteLine();
            Console.WriteLine(totalOrdersProcessed + " Orders processed.");
            Console.WriteLine("Processing stopped. Press Enter to exit.");
            Console.ReadLine();
        }
开发者ID:niujiale,项目名称:WinAzurePetShop,代码行数:33,代码来源:Program.cs

示例11: GetToken

        /// <summary>
        /// Returns token (requires user input)
        /// </summary>
        /// <returns></returns>
        public static AuthenticationResult GetToken(string authEndpoint, string tenant, string clientId)
        {
            var adalWinFormType = typeof(WebBrowserNavigateErrorEventArgs);
            Trace.WriteLine("Getting a random type from \'Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms\' to force it be deployed by mstest");

            AuthenticationResult result = null;
            var thread = new Thread(() =>
            {
                try
                {
                    var context = new AuthenticationContext(Path.Combine(authEndpoint, tenant));

                    result = context.AcquireToken(
                        resource: "https://management.core.windows.net/",
                        clientId: clientId,
                        redirectUri: new Uri("urn:ietf:wg:oauth:2.0:oob"),
                        promptBehavior: PromptBehavior.Auto);
                }
                catch (Exception threadEx)
                {
                    Console.WriteLine(threadEx.Message);
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Name = "AcquireTokenThread";
            thread.Start();
            thread.Join();

            return result;

        }
开发者ID:hovsepm,项目名称:azure-sdk-tools,代码行数:36,代码来源:TokenCloudCredentialsHelper.cs

示例12: DeviceManager_PhotoCaptured

 static void DeviceManager_PhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
 {
     Thread thread = new Thread(PhotoCaptured);
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start(eventArgs);
     //thread.Join();
 }
开发者ID:brunoklein99,项目名称:nikon-camera-control,代码行数:7,代码来源:Program.cs

示例13: btn_Cancel_Click

 private void btn_Cancel_Click(object sender, EventArgs e)
 {
     Thread thread = new Thread(new ThreadStart(ShowBuildingList)); //Tạo luồng mới
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start(); //Khởi chạy luồng
     this.Close(); //đóng Form hiện tại. (Form1)
 }
开发者ID:phuongnq,项目名称:Chapy,代码行数:7,代码来源:FrmBuilding.cs

示例14: LiveSessionTtl

        public LiveSessionTtl()
        {
            channelHandleToSensor = new Dictionary<int, TtlSensor>();
            sensorsStarted = 0;

            applicationContext = new ApplicationContext();

            //Create thread
            sessionThread = new Thread(SessionThreadStart);
            sessionThread.IsBackground = true;
            sessionThread.SetApartmentState(ApartmentState.STA);

            //Start thread
            bool noTimeout;
            sessionThreadInitException = null;
            Monitor.Enter(sessionThread);
            {
                sessionThread.Start();
                noTimeout = Monitor.Wait(sessionThread, 5000);
            }
            Monitor.Exit(sessionThread);

            //Check for initialization error
            if (sessionThreadInitException != null)
            {
                throw sessionThreadInitException;
            }
            else if (!noTimeout)
            {
                throw new Exception("Initialization timed out!");
            }

            return;
        }
开发者ID:Faham,项目名称:emophiz,代码行数:34,代码来源:LiveSessionTtl.cs

示例15: Capture

        private static Image Capture(string url, Size size)
        {
            Image result = new Bitmap(size.Width, size.Height);

            var thread = new Thread(() =>
            {
                using (var browser = new WebBrowser())
                {
                    browser.ScrollBarsEnabled = false;
                    browser.AllowNavigation = true;
                    browser.Navigate(url);
                    browser.Width = size.Width;
                    browser.Height = size.Height;
                    browser.ScriptErrorsSuppressed = true;
                    browser.DocumentCompleted += (sender,args) => DocumentCompleted(sender, args, ref result);

                    while (browser.ReadyState != WebBrowserReadyState.Complete)
                    {
                        Application.DoEvents();
                    }
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            return result;
        }
开发者ID:AlexSanseau,项目名称:Web.Screenshot,代码行数:29,代码来源:Screenshot.cs


注:本文中的System.Threading.Thread.SetApartmentState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。