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


C# Thread.SetApartmentState方法代码示例

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


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

示例1: MTATaskScheduler

        /// <summary>Initializes a new instance of the MTATaskScheduler class with the specified concurrency level.</summary>
        /// <param name="numberOfThreads">The number of threads that should be created and used by this scheduler.</param>
        /// <param name="nameFormat">The template name form to use to name threads.</param>
        public MTATaskScheduler(int numberOfThreads, string nameFormat)
        {
            // Validate arguments
            if (numberOfThreads < 1) throw new ArgumentOutOfRangeException("numberOfThreads");

            // Initialize the tasks collection
            tasks = new BlockingCollection<Task>();

            // Create the threads to be used by this scheduler
            _threads = Enumerable.Range(0, numberOfThreads).Select(i =>
                       {
                           var thread = new Thread(() =>
                           {
                               // Continually get the next task and try to execute it.
                               // This will continue until the scheduler is disposed and no more tasks remain.
                               foreach (var t in tasks.GetConsumingEnumerable())
                               {
                                   TryExecuteTask(t);
                               }
                           });
                           thread.IsBackground = true;
                           thread.SetApartmentState(ApartmentState.MTA);
                           thread.Name = String.Format("{0} - {1}", nameFormat, thread.ManagedThreadId);
                           return thread;
                       }).ToList();

            // Start all of the threads
            _threads.ForEach(t => t.Start());
        }
开发者ID:ranji,项目名称:NServiceBus,代码行数:32,代码来源:MTATaskScheduler.cs

示例2: SetClipboard

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

示例3: Capture

    protected void Capture(object sender, EventArgs e)
    {
        string url = txtUrl.Text.Trim();

        Thread thread = new Thread(delegate()
        {
            using (WebBrowser browser = new WebBrowser())
            {
                browser.ScrollBarsEnabled = false;
                browser.AllowNavigation = false;
                browser.AllowWebBrowserDrop = false;
                browser.ScriptErrorsSuppressed = true;
                browser.Navigate("www.cnn.com");
                //browser.Navigate((url, null, <data>, "Content-Type: application/x-www-form-urlencoded");)
                browser.Width = 1024;
                browser.Height = 768;
                browser.ClientSize = new Size(1024,768);
                browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DownloadCompleted);
                while ((browser.IsBusy) |  (browser.ReadyState != WebBrowserReadyState.Complete))
                {
                    System.Windows.Forms.Application.DoEvents();
                }
                //Thread.Sleep(5000);
                //browser.Dispose();
            }
        });
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
        thread.Join();
    }
开发者ID:hansparsons,项目名称:SharePage,代码行数:30,代码来源:MainPage.aspx.cs

示例4: Connection

 public void Connection()
 {
     BTN_Connect.Visible=false;
     T = new Thread(Connect);
     T.IsBackground=true;
     T.SetApartmentState(ApartmentState.STA);
     T.Start();
 }
开发者ID:frugalware,项目名称:frugal-tweak,代码行数:8,代码来源:MainWindow.cs

示例5: AddWorker

 public static void AddWorker(ThreadManager threadManager)
 {
     Interlocked.Increment(ref threadManager.activeThreads);
     var worker = new WorkThread(threadManager);
     var thread = new Thread(worker.Loop);
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start();
 }
开发者ID:erashid,项目名称:Extensions,代码行数:8,代码来源:WorkThread.cs

示例6: Generate

 public Bitmap Generate()
 {
     // Thread
     var m_thread = new Thread(_Generate);
     m_thread.SetApartmentState(ApartmentState.STA);
     m_thread.Start();
     m_thread.Join();
     return m_Bitmap;
 }
开发者ID:hansparsons,项目名称:SharePage,代码行数:9,代码来源:WebSiteToImage.cs

示例7: StartImport

 /// <summary>
 /// 
 /// </summary>
 /// <param name="sharepointConnectionId"></param>
 /// <param name="adaptername"></param>
 /// <param name="objectdefinitionId"></param>
 public void StartImport(string sharepointConnectionId, string adaptername, string workflowName, ObjectDefinition objectdefinition)
 {
     ConnectionId = sharepointConnectionId;
     AdapterName = adaptername;
     SharePointObjectDefinition = objectdefinition;
     WorkflowName = workflowName;
     MainThread = new Thread(SharePointClientImportHelper.Start);
     MainThread.Priority = ThreadPriority.Lowest;
     MainThread.SetApartmentState(ApartmentState.STA);//Creating a single threaded apartment.
     MainThread.Start();
     Thread.Sleep(100);
 }
开发者ID:femiosinowo,项目名称:sssadl,代码行数:18,代码来源:SharePointClientImportHelper.cs

示例8: Initialize

 private static void Initialize()
 {
     // Run the message loop on another thread so we're compatible with a console mode app
     var t = new Thread(() => {
         frm = new Form();
         var dummy = frm.Handle;
         frm.BeginInvoke(new MethodInvoker(() => mre.Set()));
         Application.Run();
     });
     t.SetApartmentState(ApartmentState.STA);
     t.IsBackground = true;
     t.Start();
     mre.WaitOne();
 }
开发者ID:SpaNieLa,项目名称:AndCEC,代码行数:14,代码来源:AppCommands.cs

示例9: SetClipboard

 static void SetClipboard()
 {
     var templateClass = @"
     public static class ModuleInitializer
     {
     public static void Initialize()
     {
     //Your code goes here
     }
     }";
     var thread = new Thread(() => Clipboard.SetText(templateClass));
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start();
     thread.Join();
 }
开发者ID:Fody,项目名称:ModuleInit,代码行数:15,代码来源:InitializeMethodFinder.cs

示例10: OpenURLWithData

    public void OpenURLWithData(string wszURL, IntPtr pbPostData, int cbData, IntPtr hwnd)
    {
        Thread InvokeThread;

        // Create POST data and convert it to a byte array.
        m_byteArray = new byte[cbData];
        Marshal.Copy(pbPostData, m_byteArray, 0, cbData);

        m_szUrl = wszURL;
        m_hwnd = hwnd;

        InvokeThread = new Thread(new ThreadStart(InvokeMethod));
        InvokeThread.SetApartmentState(ApartmentState.STA);
        InvokeThread.Start();
    }
开发者ID:GoshaDE,项目名称:SuperMFLib,代码行数:15,代码来源:WebHelper.cs

示例11: Run

    void Run(ThreadStart userDelegate, ApartmentState apartmentState)
    {
        lastException = null;

        var thread = new Thread(() => MultiThreadedWorker(userDelegate));
        thread.SetApartmentState(apartmentState);

        thread.Start();
        thread.Join();

        if (ExceptionWasThrown())
        {
            ThrowExceptionPreservingStack(lastException);
        }
    }
开发者ID:shiftkey,项目名称:NotifyPropertyWeaver,代码行数:15,代码来源:CrossThreadRunner.cs

示例12: RunInSta

    public void RunInSta(Action userDelegate)
    {
        lastException = null;

        var thread = new Thread(() => MultiThreadedWorker(() => userDelegate()));
        thread.SetApartmentState(ApartmentState.STA);

        thread.Start();
        thread.Join();

        if (lastException != null)
        {
            ThrowExceptionPreservingStack(lastException);
        }
    }
开发者ID:MartinDemberger,项目名称:Costura,代码行数:15,代码来源:CrossThreadRunner.cs

示例13: IEBrowser

    /// <summary>
    /// class constructor 
    /// </summary>
    /// <param name="visible">whether or not the form and the WebBrowser control are visiable</param>
    /// <param name="userName">client user name</param>
    /// <param name="password">client password</param>
    /// <param name="resultEvent">functionality to keep the main thread waiting</param>
    public IEBrowser(bool visible, string URL, AutoResetEvent resultEvent)
    {
        //this.userName = userName;
        //this.password = password;
        this.resultEvent = resultEvent;
        htmlResult = null;

        thrd = new Thread(new ThreadStart(
            delegate {
                Init(visible,URL);
                System.Windows.Forms.Application.Run(this);
            }));
        // set thread to STA state before starting
        thrd.SetApartmentState(ApartmentState.STA);
        thrd.Start();
    }
开发者ID:yangdayuan,项目名称:mylab,代码行数:23,代码来源:IEBrowser.cs

示例14: setNorth_Click

    protected void setNorth_Click(object sender, EventArgs e)
    {
        northNetwork = (sender as Button).Text.ToUpper();

        // Do work!
        Thread threadNorth = new Thread( () =>
        {
            using ( System.Windows.Forms.WebBrowser webBrowser1 = new System.Windows.Forms.WebBrowser() )
            {
                webBrowser1.DocumentCompleted += loadPresetsPage;
                webBrowser1.Navigate( NORTH_URL_SET_PRESET );
                System.Windows.Forms.Application.Run();
            }
        } );
        threadNorth.Name = "North";
        threadNorth.SetApartmentState( ApartmentState.STA );
        threadNorth.Start();
        threadNorth.Join();
    }
开发者ID:jlam916,项目名称:ServiceDesk,代码行数:19,代码来源:TrainingRooms.aspx.cs

示例15: RunAsync

 public Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments,
     ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource)
 {
     var tcs = new TaskCompletionSource<RunSummary>();
     var thread = new Thread(() =>
     {
         try
         {
             var testCaseTask = testCase.RunAsync(diagnosticMessageSink, messageBus, constructorArguments, aggregator,
                 cancellationTokenSource);
             tcs.SetResult(testCaseTask.Result);
         }
         catch (Exception e)
         {
             tcs.SetException(e);
         }
     });
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start();
     return tcs.Task;
 }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:21,代码来源:STATestCase.cs


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