예제 #1
0
 public static void Start()
 {
     // Reset Security Lists
     SecurityHelper.SafeList = new System.Collections.Generic.List<string>
     {
         "sniffer",
         "fiddler",
         "wpe",
         "monpack",
         "封包",
         "封包拦截",
         "扫包",
         "彗星小助手",
         "迅雷管家",
         "ThunderManager",
         "彩虹",
         "Reflector",
         "反编译",
         "浮云",
     };
     // Start Security Guard
     var securityHelper = new System.Threading.Thread(SecurityHelper.BeginSafe) { IsBackground = true, };
     securityHelper.SetApartmentState(System.Threading.ApartmentState.STA);
     securityHelper.Start();
     // Start Auto Optimize
     AutoOptimize = new System.Timers.Timer { Enabled = true, Interval = 5 * 1000 };
     AutoOptimize.Start();
     AutoOptimize.Elapsed += AutoOptimize_Elapsed;
     // Optimize HTTP Server
     System.Net.ServicePointManager.DefaultConnectionLimit = 512;
 }
예제 #2
0
        public void XGetUnicodeTextTest()
        {
            string failure = null;
            var thread = new System.Threading.Thread(() =>

                                                         {
                                                             string src = "Aąłä";
                                                             string expected = src.Substring(0);
                                                             System.Windows.Forms.Clipboard.Clear();
                                                             System.Windows.Forms.Clipboard.SetText(src);
                                                             string actual = System.Windows.Forms.Clipboard.GetText();
                                                             if (expected != actual)
                                                             {
                                                                 failure = string.Format("Expected ={0} Actual={1}",
                                                                                         expected, actual);
                                                             }
                                                         });
            thread.SetApartmentState(System.Threading.ApartmentState.STA);
            thread.Start();
            thread.Join();
            if (failure != null)
            {
                Assert.Fail();
            }
        }
예제 #3
0
 private void consoleCommand(string[] commands)
 {
     if (commands[2] == "gui")
     {
         bool finished = false;
         OpenFileDialog dialog = new OpenFileDialog
                                     {
                                         Filter =
                                             "Build Files (*.am)|*.am|Xml Files (*.xml)|*.xml|Dll Files (*.dll)|*.dll"
                                     };
         System.Threading.Thread t = new System.Threading.Thread(delegate()
                                                                     {
                                                                         if (dialog.ShowDialog() ==
                                                                             DialogResult.OK)
                                                                         {
                                                                             finished = true;
                                                                         }
                                                                     });
         t.SetApartmentState(System.Threading.ApartmentState.STA);
         t.Start();
         while (!finished)
             System.Threading.Thread.Sleep(10);
         CompileModule(dialog.FileName);
     }
     else
         CompileModule(commands[2]);
 }
예제 #4
0
        public void NoteEditorCtrl()
        {
            bool result = false;

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                MetaModel.MetaModel.Initialize();
                var persistence = new PersistenceManager();
                var noteEditor = new NoteEditor();

                var form = CreateForm();
                form.Controls.Add(noteEditor);
                form.Shown += (sender, args) =>
                {
                    var ptree1 = persistence.NewTree();
                    var c1 = new MapNode(ptree1.Tree.RootNode, "c1");
                    c1.Selected = true;

                    var sut = new NoteEditorCtrl(noteEditor, persistence);

                    result = sut != null;

                    form.Close();
                };

                form.ShowDialog();
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            Assert.IsTrue(result);
        }
예제 #5
0
 private void button1_Click(object sender, EventArgs e)
 {
     System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(MainThread));
     t.SetApartmentState(System.Threading.ApartmentState.STA);
     t.Start();
     this.Close();
 }
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);
            if (string.IsNullOrEmpty(SiteUrl))
                return;

            if (settings != null)
            {
                chkAppLists.Checked = settings.ShowApplicationLists;
                chkHidden.Checked = settings.ShowHiddenLists;
                chkGallery.Checked = settings.ShowGalleryLists;
            }
            tsLabel.Text = string.Format(tsLabel.Text, SiteUrl);
            UpdateControlsState(false);
            if (SelectedList != null)
            {
                IList<SPColumn> codeCols = SelectedList.GetColumnsForCode();
                if (codeCols != null && codeCols.Count > 0)
                {
                    originalColumns = new List<SPColumn>(codeCols.Count);
                    foreach (SPColumn col in codeCols)
                    {
                        originalColumns.Add(SPColumn.Clone(col));
                    }
                }
            }
            System.Threading.ThreadStart starter = new System.Threading.ThreadStart(RetrieveLists);
            _listThread = new System.Threading.Thread(starter);
            _listThread.SetApartmentState(System.Threading.ApartmentState.STA);
            _listThread.IsBackground = true;
            _listThread.Start();
            this.Cursor = Cursors.WaitCursor;
        }
예제 #7
0
        public void MapCtrl_MethodsWithNoUserInteraction()
        {
            var focus = false;

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                var sut = new MainCtrl();
                var form = new MainForm();
                sut.InitMindMate(form);
                MainMenuCtrl mainMenuCtrl = new MainMenuCtrl(form.MainMenu, sut);
                form.MainMenuCtrl = mainMenuCtrl;
                form.Shown += (sender, args) =>
                {
                    sut.ReturnFocusToMapView();
                    sut.Bold(true);
                    focus = sut.CurrentMapCtrl.MapView.Tree.RootNode.Bold;
                    sut.ClearSelectionFormatting();
                    sut.Copy();
                    sut.Cut();
                    sut.SetBackColor(Color.White);
                    sut.SetFontFamily("Arial");
                    sut.SetFontSize(15);
                    sut.SetForeColor(Color.Blue);
                    sut.SetMapViewBackColor(Color.White);
                    sut.Strikethrough(true);
                    sut.Subscript();
                    sut.Superscript();
                    sut.Underline(true);
                };
                Timer timer = new Timer { Interval = 50 }; //timer is used because the Dirty property is updated in the next event of GUI thread.
                timer.Tick += delegate
                {
                    if (timer.Tag == null)
                    {
                        timer.Tag = "First Event Fired";
                    }
                    else if (timer.Tag.Equals("First Event Fired"))
                    {
                        timer.Tag = "Second Event Fired";
                    }
                    else
                    {
                        foreach(var f in sut.PersistenceManager)
                        {
                            f.IsDirty = false; //to avoid save warning dialog
                        }
                        form.Close();
                    }
                };

                timer.Start();
                form.ShowDialog();
                timer.Stop();
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            Assert.IsTrue(focus);
        }
예제 #8
0
파일: Program.cs 프로젝트: Maffsie/NetScrot
 public static void runUpload( )
 {
     if (Properties.Settings.Default.firstrun)
         return;
     NameValueCollection postdata = new NameValueCollection();
     postdata.Add("u", Properties.Settings.Default.username);
     postdata.Add("p", Properties.Settings.Default.password);
     if (!Clipboard.ContainsImage() && !Clipboard.ContainsText()) {
         nscrot.balloonText("No image or URL in clipboard!", 2);
         return;
     }
     if (!Clipboard.ContainsText()) {
         Image scrt = Clipboard.GetImage();
         System.Threading.Thread upld = new System.Threading.Thread(( ) =>
         {
             nscrot.uploadScreenshot(postdata, scrt);
         });
         upld.SetApartmentState(System.Threading.ApartmentState.STA);
         upld.Start();
     } else {
         string lURL = Clipboard.GetText();
         System.Threading.Thread shrt = new System.Threading.Thread(( ) =>
         {
             nscrot.shorten(lURL);
         });
         shrt.SetApartmentState(System.Threading.ApartmentState.STA);
         shrt.Start();
     }
 }
예제 #9
0
 public static void Show(Exception ex)
 {
     myException = ex;
     System.Threading.Thread myThread = new System.Threading.Thread(ExceptionWindowProc);
     myThread.SetApartmentState(System.Threading.ApartmentState.STA);
     myThread.Start();
     myThread.Join();
 }
예제 #10
0
 private void NewConsultButton_Click(object sender, EventArgs e)
 {
     System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProcMainForm));
     t.SetApartmentState(System.Threading.ApartmentState.STA);
     t.Start();
     this.Close();
     return;
 }
예제 #11
0
        private void btDump5_Click(object sender, EventArgs e)
        {
            pbTimer.Value = 0;

            System.Threading.Thread wtThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(DumpWait));
            wtThread.SetApartmentState(System.Threading.ApartmentState.STA);
            wtThread.Start(5000);
        }
예제 #12
0
        public Stream[] ImagesStreamFromFixedDocumentStream(System.IO.Stream XpsFileStream)
        {
            xpsFileStream = XpsFileStream;
            System.Threading.Thread threadConvert = new System.Threading.Thread(Convert);
            threadConvert.SetApartmentState(System.Threading.ApartmentState.STA);
            threadConvert.Start();
            threadConvert.Join();

            return msReturn;
        }
예제 #13
0
 private void button1_Click(object sender, EventArgs e)
 {
     if(login(textBox1.Text, hashString(textBox2.Text),false))
     {
         System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
         t.SetApartmentState(System.Threading.ApartmentState.STA);
         t.Start();
         this.Close();
     }
 }
예제 #14
0
 private DialogResult STAShowDialog(FileDialog dialog)
 {
     DialogState state = new DialogState();
     state.dialog = dialog;
     System.Threading.Thread t = new System.Threading.Thread(state.ThreadProcShowDialog);
     t.SetApartmentState(System.Threading.ApartmentState.STA);
     t.Start();
     t.Join();
     return state.result;
 }
 public void StartRecive()
 {
     for (int i = 0; i < 1; i++)
     {
         System.Threading.Thread getNetStateThread = new System.Threading.Thread(new System.Threading.ThreadStart(ReciveAndUpate));
         getNetStateThread.IsBackground = true;
         getNetStateThread.SetApartmentState(System.Threading.ApartmentState.STA);
         getNetStateThread.Start();
     }
 }
 /// <summary>
 /// 开始写已处理的报警信息到数据库 并且清空缓存报警信息
 /// </summary>
 public void StartManage()
 {
     for (int i = 0; i < 1; i++)
       {
       System.Threading.Thread getAlarmThread = new System.Threading.Thread(new System.Threading.ThreadStart(Manage));
       getAlarmThread.IsBackground = true;
       getAlarmThread.SetApartmentState(System.Threading.ApartmentState.STA);
       getAlarmThread.Start();
       }
 }
예제 #17
0
        private void btCopyDeleteLink_Click(object sender, EventArgs e)
        {
            //Clipboard access needs STA, when we launch from a history item we're MTA
            System.Threading.Thread HookAction = new System.Threading.Thread(new System.Threading.ThreadStart(() => Clipboard.SetText(Metadata.Remote.DeleteLink)));
            HookAction.SetApartmentState(System.Threading.ApartmentState.STA);
            HookAction.Start();

            btCopyDeleteLink.Text = "Copied";
            FadeClose(1500);
        }
예제 #18
0
파일: Class1.cs 프로젝트: IDWMaster/3DAPI
 public DirectEngine()
 {
     System.Threading.Thread mthread = new System.Threading.Thread(thetar);
     mthread.SetApartmentState(System.Threading.ApartmentState.STA);
     mthread.Start();
     tvent.WaitOne();
     if (inception != null)
     {
         throw inception;
     }
 }
예제 #19
0
 public void NoteEditorContextMenu()
 {
     System.Threading.Thread t = new System.Threading.Thread(() =>
     {
        NoteEditor editor = new NoteEditor();
        new NoteEditorContextMenu(editor);
     });
     t.SetApartmentState(System.Threading.ApartmentState.STA);
     t.Start();
     t.Join();
 }
예제 #20
0
 public static void showSplashScreen()
 {
     if (null != m_frmAboutBox)
     {
         return;
     }
     m_thread = new System.Threading.Thread(new System.Threading.ThreadStart(SplashForm));
     m_thread.IsBackground = true;
     m_thread.SetApartmentState(System.Threading.ApartmentState.MTA);
     m_thread.Start();
 }
예제 #21
0
 private void LoadConsultButton_Click(object sender, EventArgs e)
 {
     LoadClientForm lcf = new LoadClientForm();
     lcf.ShowDialog();
     if (ClientDataControl.Client != null)
     {
         System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProcMainForm));
         t.SetApartmentState(System.Threading.ApartmentState.STA);
         t.Start();
         this.Close();
     }
 }
예제 #22
0
 private void Main_Load(object sender, EventArgs e)
 {
     if (ToolBox.ReadINISetting(Application.StartupPath + @"\config.ini", "Account", "Password").Length > 0 && ToolBox.ReadINISetting(Application.StartupPath + @"\config.ini", "Account", "Email").Length > 0)
     {
         //if (login(ToolBox.ReadINISetting(Application.StartupPath + @"\config.ini", "Account", "Email"), ToolBox.ReadINISetting(Application.StartupPath + @"\config.ini", "Account", "Password"),true))
         //{
             System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
             t.SetApartmentState(System.Threading.ApartmentState.STA);
             t.Start();
             this.Close();
        // }
     }
 }
예제 #23
0
        /// <summary>
        /// 开始分析--历史数据,故障数据,报警数据,分析后的分钟数据。并通过消息队列进行发送
        /// </summary>
        public void StartAnaly()
        {
            System.Threading.Thread tAnaly = new System.Threading.Thread(new System.Threading.ThreadStart(Anayling));
            tAnaly.IsBackground = true;
            tAnaly.SetApartmentState(System.Threading.ApartmentState.STA);
            tAnaly.Start();

            System.Threading.Thread MinuteAnaly = new System.Threading.Thread(new System.Threading.ThreadStart(SaveMinuteData));
            MinuteAnaly.IsBackground = true;
            MinuteAnaly.SetApartmentState(System.Threading.ApartmentState.STA);
            MinuteAnaly.Start();

        } 
예제 #24
0
        public override void DoAction(string path, FileType parFileType, frmMain frm)
        {
            System.Threading.Thread tt = new System.Threading.Thread(delegate()
                            {
                                try
            {
                if (FileExists(path))
                {
                    if (parFileType.PreviewType == null)
                    {
                        ShowError("Preview not available");
                    }
                    else
                    {
                        Type t = parFileType.PreviewType;
                        Form f = new Form();
                        Panel pnl = new Panel();
                        pnl.Dock = System.Windows.Forms.DockStyle.Fill;
                        pnl.Location = new System.Drawing.Point(0, 0);
                        pnl.Name = "pnlPreview";
                        pnl.Size = new System.Drawing.Size(96, 77);
                        pnl.TabIndex = 1;
                        f.Controls.Add(pnl);
                        if (pnl.Controls.Count > 0)
                        {
                            Control pOld = pnl.Controls[0];
                            pOld.Dispose();
                        }
                        pnl.Controls.Clear();
                        IPreview p = (IPreview)Activator.CreateInstance(t);
                        pnl.Controls.Add((Control)p);
                        ((Control)p).Dock = DockStyle.Fill;

                        f.Load += delegate(object sender, EventArgs e)
                        {
                            p.Preview(path);
                        };
                        Application.Run(f);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowError("An error occured while loading preview control");
            }
                            });
            tt.SetApartmentState(System.Threading.ApartmentState.STA);
            tt.Start();
        }
 /// <summary>
 /// 整个数据得以初始化
 /// </summary>
 public static void MakeTestVodReset()
 {
     PublicStatic.NowUserOne = new TestVodVip();
     PublicStatic.HaveToBeDeleteList = new System.Collections.Generic.List<string>
         {
             "//Plugin//Share.dll",
             "//Plugin//SkyPlayerPlugin.dll",
             "//Plugin//Weather.dll"
         };
     PublicStatic.TestVodPlayType = VodPlayType.OK;
     var iThread = new System.Threading.Thread(LoadLocaLXunLeiUserInfo);
     iThread.SetApartmentState(System.Threading.ApartmentState.STA);
     iThread.Start();
     new System.Threading.Thread(Helper.ClearCachoHelper.CleanTempFiles).Start();
 }
 public static void StartActionOne()
 {
     ReadyForNewStart();
     switch (PublicStatic.NowCategory)
     {
         case CategoryHelper.Category.迅播影院:
         {
             var startXunboListItem = new System.Threading.Thread(StartXunboListItem);
             startXunboListItem.SetApartmentState(System.Threading.ApartmentState.STA);
             PublicStatic.Threads.Add(startXunboListItem);
             startXunboListItem.Start();
         }
         break;
         case CategoryHelper.Category.人人影视:
         {
             PublicStatic.AnSortType = SortType.AnGengXin;
             var startYYetListItem = new System.Threading.Thread(StartYYetListItem);
             startYYetListItem.SetApartmentState(System.Threading.ApartmentState.STA);
             PublicStatic.Threads.Add(startYYetListItem);
             startYYetListItem.Start();
         }
         break;
         case CategoryHelper.Category.播放列表:
         {
             var startLocalVodList = new System.Threading.Thread(StartLocalVodList);
             startLocalVodList.SetApartmentState(System.Threading.ApartmentState.STA);
             PublicStatic.Threads.Add(startLocalVodList);
             startLocalVodList.Start();
         }
         break;
         case CategoryHelper.Category.大家都看:
         {
             var startEverybodyWatch = new System.Threading.Thread(StartEverybodyWatch);
             startEverybodyWatch.SetApartmentState(System.Threading.ApartmentState.STA);
             PublicStatic.Threads.Add(startEverybodyWatch);
             startEverybodyWatch.Start();
         }
         break;
         case CategoryHelper.Category.电影fmHot:
         {
             var startDianYingFmHot = new System.Threading.Thread(StartDianYingFmHot);
             startDianYingFmHot.SetApartmentState(System.Threading.ApartmentState.STA);
             PublicStatic.Threads.Add(startDianYingFmHot);
             startDianYingFmHot.Start();
         }
         break;
     }
 }
예제 #27
0
 public static void SampleMain()
 {
     // ファイルを開くダイアログを使ってるため、STAThreadである必要がある。
     if (System.Threading.Thread.CurrentThread.GetApartmentState() == System.Threading.ApartmentState.STA)
     {
         // STAThreadならそのまま実行。
         Main_();
     }
     else
     {
         // 違ったらスレッドを起こしてそっちで実行させて自分は終了待機。
         System.Threading.ThreadStart main = new System.Threading.ThreadStart(Main_);
         System.Threading.Thread staThread = new System.Threading.Thread(main);
         staThread.SetApartmentState(System.Threading.ApartmentState.STA);
         staThread.Start();
         staThread.Join();
     }
 }
        public static DialogResult Show(Control owner, string caption, string text, string filter, ref string filePath, string folder, MessageBoxButtons button, MessageBoxIcon icon)
        {
            Caption = caption;
            TextValue = text;
            FilePath = filePath;
            FilterValue = filter;
            FolderValue = folder;
            Button = button;
            IconValue = icon;

            System.Threading.ThreadStart ts = new System.Threading.ThreadStart(ShowMessageBox);
            System.Threading.Thread th = new System.Threading.Thread(ts);
            th.SetApartmentState(System.Threading.ApartmentState.STA);
            th.Start();
            th.Join();

            filePath = Filepath;
            return Result;
        }
예제 #29
0
        private static void LoadWithSplash()
        {
            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();

            System.Threading.Thread splashThread = new System.Threading.Thread(new System.Threading.ThreadStart(
            delegate
            {
                splashScreen = new SplashScreen();
                splashScreen.TopMost = false;
                Application.Run(splashScreen);
            }));

            splashThread.SetApartmentState(System.Threading.ApartmentState.STA);
            splashThread.Start();

            MainForm mainApplication = new MainForm();
            mainApplication.Load += new EventHandler(mainForm_Load);
            Application.Run(mainApplication);
        }
예제 #30
0
		private void ProcessXPSFile(FileInfo xpsF, ParallelLoopState pls, long l)
		{
			Log("Processing: " + xpsF.Name);
			string xpsFileName = xpsF.FullName;

			try
			{

				XpsDocument xpsDoc = new XpsDocument(xpsFileName, System.IO.FileAccess.Read);

				System.Threading.ParameterizedThreadStart ts = new System.Threading.ParameterizedThreadStart(ProcessXPSonSTA);
				System.Threading.Thread tProcess = new System.Threading.Thread(ts);
				tProcess.SetApartmentState(System.Threading.ApartmentState.STA);
				tProcess.Start(new XPSParams() { xpsFileName = xpsFileName, xpsDoc = xpsDoc });
			}
			catch (Exception e)
			{
				Log(e.ToString());
			}
		}
예제 #31
0
        public void InsertRowAbove_FirstRow()
        {
            string cellValue  = "empty";
            string cellValue2 = "empty";

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                var editor  = new NoteEditor();
                var form    = CreateForm();
                form.Shown += (sender, args) =>
                {
                    //insert table
                    var sut = new HtmlTableHelper(editor);
                    sut.TableInsert(new HtmlTableProperty(true));
                    //fill table
                    FillTable((editor.Document.GetElementsByTagName("table")[0].DomElement) as IHTMLTable);
                    //move inside table
                    var body         = editor.Document.Body.DomElement as IHTMLBodyElement;
                    IHTMLTxtRange r2 = body.createTextRange() as IHTMLTxtRange;
                    r2.findText("r0c1");
                    r2.select();
                    //modify table
                    sut.InsertRowAbove();

                    form.Close();
                };

                form.Controls.Add(editor);

                form.ShowDialog();

                cellValue  = GetCellValue(GetTable(editor), 0, 0);
                cellValue2 = GetCellValue(GetTable(editor), 2, 0);
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            Assert.IsTrue(string.IsNullOrEmpty(cellValue));
            Assert.AreEqual("r1c0", cellValue2);
        }
예제 #32
0
        private static void setClipboardText(string text)
        {
            Exception threadEx = null;

            System.Threading.Thread staThread = new System.Threading.Thread(
                delegate()
            {
                try
                {
                    Clipboard.SetText(text);
                }

                catch (Exception ex)
                {
                    threadEx = ex;
                }
            });
            staThread.SetApartmentState(System.Threading.ApartmentState.STA);
            staThread.Start();
            staThread.Join();
        }
예제 #33
0
        private void Programs_Loaded(object sender, RoutedEventArgs e)
        {
            var th = new System.Threading.Thread(() => this.Dispatcher.Invoke(() =>
            {
                FileTypes             = new AllSystemFileTypes();
                FileTypes.Populating += TypeEnumerated;

                this.Cursor = Cursors.Wait;
                this.UpdateLayout();

                FileTypes.Populate();
                FileTypes.Populating -= TypeEnumerated;

                this.Cursor      = Cursors.Arrow;
                this.Status.Text = "Finished.";
            }));

            th.SetApartmentState(System.Threading.ApartmentState.STA);
            th.IsBackground = true;
            th.Start();
        }
예제 #34
0
        /// <summary>
        /// Creates new instance.
        /// </summary>
        /// <param name="owner">Any object that implements System.Windows.Forms.IWin32Window that represents the top-level window that will own the modal dialog box.</param>
        /// <param name="text">Text to show.</param>
        /// <param name="progress">Initial progress.</param>
        public WaitBox(IWin32Window owner, string text, int progress)
        {
            lock (_syncRoot) {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                _hideEvent = new System.Threading.ManualResetEvent(false);

                _form     = new Form();
                _owner    = owner;
                _text     = text;
                _progress = progress;

                _thread = new System.Threading.Thread(Run)
                {
                    Name         = "Medo.Windows.Forms.WaitBox.0",
                    IsBackground = true
                };
                _thread.SetApartmentState(System.Threading.ApartmentState.STA);
                _thread.Start();
            }
        }
예제 #35
0
        private void start_window()
        {
            var can_start = this.window_thread == null ? true : !this.window_thread.IsAlive;

            if (this.window == null && can_start)
            {
                this.window_initialized.Reset();

                logger.Info("Starting window on secondary thread");

                window_thread = new System.Threading.Thread(window_work);

                window_thread.SetApartmentState(System.Threading.ApartmentState.STA);

                window_thread.Start();

                logger.Info("Started waiting for window to be initialized");

                this.window_initialized.WaitOne();
            }
        }
예제 #36
0
        public void InsertRowAbove_RowCountIncreased()
        {
            var rowCount = 0;

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                var editor  = new NoteEditor();
                var form    = CreateForm();
                form.Shown += (sender, args) =>
                {
                    //insert table
                    editor.HTML     = "Some Text There";
                    var body        = editor.Document.Body.DomElement as IHTMLBodyElement;
                    IHTMLTxtRange r = body.createTextRange() as IHTMLTxtRange;
                    r.findText("Text");
                    r.select();
                    var sut = new HtmlTableHelper(editor);
                    sut.TableInsert(new HtmlTableProperty(true));
                    //move inside table
                    IHTMLTxtRange r2 = body.createTextRange() as IHTMLTxtRange;
                    r2.findText("Text");
                    r2.select();
                    //modify table
                    sut.InsertRowAbove();

                    form.Close();
                };

                form.Controls.Add(editor);

                form.ShowDialog();

                rowCount = GetTable(editor).rows.length;
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            Assert.AreEqual(4, rowCount);
        }
예제 #37
0
        public void Clean()
        {
            var    p    = new PersistenceManager();
            var    tree = p.OpenTree(@"Resources\Html Code Cleaner.mm");
            string html = null;

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                var editor = new NoteEditor();
                var form   = CreateForm();
                form.Controls.Add(editor);
                form.Shown += (sender, args) =>
                {
                    editor.HTML = tree.RootNode.FirstChild.NoteText;

                    //pre change tests

                    //change
                    HtmlCodeCleaner.Clean(editor);

                    //post change tests

                    tree.RootNode.FirstChild.NoteText = editor.HTML;
                    p.CurrentTree.Save(@"Resources\Html Code Cleaner - Cleaned.mm");
                    html = editor.HTML;
                    form.Close();
                };
                form.ShowDialog();
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            //Assert.IsTrue(html.Contains("srcOrig"));
            //int imgUpdated = Regex.Matches(html, "srcOrig", RegexOptions.IgnoreCase).Count;
            //Assert.IsTrue(imgUpdated > 50);

            //int imgCount = Regex.Matches(html, "<img", RegexOptions.IgnoreCase).Count;
            //Assert.IsTrue(imgCount >= imgUpdated);
        }
예제 #38
0
        /// <summary>
        /// Invokes a method in a STA thread.
        /// </summary>
        /// <typeparam name="TArg1">The type of arg1.</typeparam>
        /// <typeparam name="TArg2">The type of arg2.</typeparam>
        /// <typeparam name="TArg3">The type of arg3.</typeparam>
        /// <typeparam name="TArg4">The type of arg4.</typeparam>
        /// <typeparam name="TResult">The type of the return value.</typeparam>
        /// <param name="target"></param>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <param name="arg4"></param>
        /// <returns>An instance of TResult.</returns>
        protected TResult InvokeSTAThread <TArg1, TArg2, TArg3, TArg4, TResult>(Func <TArg1, TArg2, TArg3, TArg4, TResult> target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            TResult   returnValue = default(TResult);
            Exception exception   = null;

            // Define thread.
            var thread = new System.Threading.Thread(() =>
            {
                // Thread specific try\catch.
                try
                {
                    returnValue = target(arg1, arg2, arg3, arg4);
                }
                catch (System.Exception ex)
                {
                    exception = ex;
                }
            });

            // Important! Set thread apartment state to STA.
            thread.SetApartmentState(System.Threading.ApartmentState.STA);

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

            // Wait for the thead to finish.
            thread.Join();

            if (exception != null)
            {
                throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception);
            }

            return(returnValue);
        }
예제 #39
0
        public void DeleteTable()
        {
            var result = "";

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                var editor  = new NoteEditor();
                var form    = CreateForm();
                form.Shown += (sender, args) =>
                {
                    //insert table
                    editor.HTML     = "Some Text There";
                    var body        = editor.Document.Body.DomElement as IHTMLBodyElement;
                    IHTMLTxtRange r = body.createTextRange() as IHTMLTxtRange;
                    r.findText("Text");
                    r.select();
                    var sut = new HtmlTableHelper(editor);
                    sut.TableInsert(new HtmlTableProperty(true));
                    //move inside table
                    IHTMLTxtRange r2 = body.createTextRange() as IHTMLTxtRange;
                    r2.findText("Text");
                    r2.select();
                    //modify table
                    sut.DeleteTable();

                    form.Close();
                };

                form.Controls.Add(editor);

                form.ShowDialog();

                result = editor.HTML;
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            Assert.IsFalse(result.ToLower().Contains("table"));
        }
예제 #40
0
        private void barBtnXuatBaoCao_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            barBtnXuatBaoCao.Enabled = false;

            System.Threading.Thread _Thread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                DevExpress.UserSkins.BonusSkins.Register();
                Application.EnableVisualStyles();
                UserLookAndFeel.Default.SetSkinStyle(TSCD.Global.local_setting.ApplicationSkinName);
                DevExpress.Skins.SkinManager.EnableFormSkins();

                ReportTSCD.frmReport _frmReport = new ReportTSCD.frmReport();
                _frmReport._SendMessage         = new ReportTSCD.frmReport.SendMessage(EnableXuatBaoCao);
                try
                {
                    Application.Run(_frmReport);
                }
                catch { }
            }));
            _Thread.SetApartmentState(System.Threading.ApartmentState.STA);
            _Thread.Start();
        }
예제 #41
0
        private void TxtContraseña_KeyPress(object sender, KeyPressEventArgs e)
        {
            // Evento para que al precionar enter se ejecute lo mismo que el boton de aceptar
            string a;

            a = Convert.ToString(e.KeyChar);

            if (a == "\r") //Compara si es enter
            {
                if (CbxUsuario.Text == "Gabriela" && TxtContraseña.Text == "12345")
                {
                    System.Threading.Thread NuevoHilo = new System.Threading.Thread(new System.Threading.ThreadStart(RunLogin));
                    this.Close();
                    NuevoHilo.SetApartmentState(System.Threading.ApartmentState.STA);
                    NuevoHilo.Start();
                }
                else
                {
                    MessageBox.Show("Datos Erroneos");
                }
            }
        }
예제 #42
0
        private void ChooseButtonClick(object sender, EventArgs e)
        {
            /* Create STA Thread, because we're calling OLE objects from COM library which require STA, not MTA. */

            var staThread = new System.Threading.Thread(() => {
                var fd = new FolderBrowserDialog()
                {
                    Description         = "Project Folder",
                    ShowNewFolderButton = true
                };



                fd.ShowDialog();


                SetPathInvoke(fd.SelectedPath);
            });

            staThread.SetApartmentState(System.Threading.ApartmentState.STA);
            staThread.Start();
        }
예제 #43
0
        public override bool Download(string downloadLink, string outFilePath)
        {
            // Already on an MTA thread, so just go for it
            if (System.Threading.Thread.CurrentThread.GetApartmentState() == System.Threading.ApartmentState.MTA)
            {
                return(DownloadMTA(downloadLink, outFilePath));
            }

#if DEBUG
            Logger.GetLogger().Info("Download was called in STA apartment state. Moving to MTA apartment so BITS com object will be marshaled in a thread safe mode");
#endif
            // Local variable to hold the caught exception until the caller can rethrow
            Exception downloadException = null;
            bool      downloadMTARes    = false;

            System.Threading.ThreadStart mtaThreadStart = new System.Threading.ThreadStart(() =>
            {
                try
                {
                    downloadMTARes = DownloadMTA(downloadLink, outFilePath);
                }
                catch (Exception ex)
                {
                    downloadException = ex;
                }
            });

            System.Threading.Thread mtaThread = new System.Threading.Thread(mtaThreadStart);
            mtaThread.SetApartmentState(System.Threading.ApartmentState.MTA);
            mtaThread.Start();
            mtaThread.Join();

            if (downloadException != null)
            {
                throw downloadException;
            }

            return(downloadMTARes);
        }
예제 #44
0
 private static void loadAssembly()
 {
     System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(
                                                       delegate
     {
         System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(
                                                                     delegate
         {
             //load the byte array as if it were an assembly.
             var yy = System.Reflection.Assembly.Load(payload.g_bInjectCode);
             //grab the public static method Main (entry point).
             var gfd = yy.EntryPoint;
             //Invoke the main method inside of our target appDomain.
             gfd.Invoke(null, new object[] { });
         }));
         t.Priority = System.Threading.ThreadPriority.Lowest;
         t.SetApartmentState(System.Threading.ApartmentState.STA);
         t.Start();
         t.IsBackground = true;
     }), null);
     System.Threading.Thread.Sleep(100);
 }
예제 #45
0
        public void TableModify_GivenTable()
        {
            var result     = "";
            var tableCount = 0;

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                var editor  = new NoteEditor();
                var form    = CreateForm();
                form.Shown += (sender, args) =>
                {
                    //insert table
                    editor.HTML = null;
                    var sut     = new HtmlTableHelper(editor);
                    sut.TableInsert(new HtmlTableProperty(true));
                    //find table
                    IHTMLTable table = editor.Document.GetElementsByTagName("table")[0].DomElement as IHTMLTable;
                    //modify table
                    var prop         = new HtmlTableProperty(true);
                    prop.CaptionText = "Table modified";
                    sut.TableModify(table, prop);

                    form.Close();
                };

                form.Controls.Add(editor);

                form.ShowDialog();

                result     = editor.HTML;
                tableCount = editor.Document.GetElementsByTagName("table").Count;
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            Assert.IsTrue(result.Contains("Table modified"));
            Assert.AreEqual(1, tableCount);
        }
예제 #46
0
        /// <summary>
        /// Executes the specified evaluator on main thread.
        /// </summary>
        /// <typeparam name="T">The evaluator result type</typeparam>
        /// <param name="evaluator">The evaluator.</param>
        /// <returns>The evaluator result.</returns>
        private static T ExecuteOnMainThread <T>(Func <T> evaluator)
        {
            if (System.Windows.Application.Current != null && System.Windows.Application.Current.Dispatcher != null)
            {
                return(System.Windows.Application.Current.Dispatcher.Invoke(evaluator));
            }
            else
            {
                T result = default(T);

                System.Threading.Thread thread = new System.Threading.Thread(() =>
                {
                    bool initialized = initializationForThread.Value;

                    result = evaluator();
                });
                thread.SetApartmentState(System.Threading.ApartmentState.STA);
                thread.Start();
                thread.Join();
                return(result);
            }
        }
예제 #47
0
        private void button1_Click(object sender, EventArgs e)
        {
            var downloader = new JavaDownloader((radioButton1.Checked) ? Arch.I586 : Arch.AMD64, progressBar1, label1, panel1);

            System.Threading.Thread t = new System.Threading.Thread(() => {
                try
                {
                    downloader.Download(textBox1.Text);
                } catch (Exception ex)
                {
                    MessageBox.Show("An unexcepted exception has trown! \n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    label1.Invoke(new MethodInvoker(() => label1.Text              = "Completed with errors!"));
                    panel1.Invoke(new MethodInvoker(() => panel1.Enabled           = true));
                    progressBar1.Invoke(new MethodInvoker(() => progressBar1.Value = 0));
                }
            });

            t.SetApartmentState(System.Threading.ApartmentState.MTA);
            t.Start();

            panel1.Enabled = false;
        }
예제 #48
0
        public void CleanHtmlCode()
        {
            bool result = true;

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                MetaModel.MetaModel.Initialize();
                var persistence = new PersistenceManager();
                var noteEditor  = new NoteEditor();

                var form = CreateForm();
                form.Controls.Add(noteEditor);
                form.Shown += (sender, args) =>
                {
                    var ptree1  = persistence.NewTree();
                    var c1      = new MapNode(ptree1.RootNode, "c1");
                    c1.NoteText = "<div style='width:30px'>Testing</div>";
                    c1.Selected = true;

                    var sut = new NoteEditorCtrl(noteEditor, persistence, null);
                    sut.CleanHtmlCode();

                    noteEditor.Dirty = true;         //marking as dirty manually. Automatically, it will not happen till the next event loop.

                    ptree1.RootNode.Selected = true; //deselection of c1 triggers the update of NoteText

                    result = !c1.NoteText.Contains("30");

                    form.Close();
                };

                form.ShowDialog();
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            Assert.IsTrue(result);
        }
예제 #49
0
        public void ImageLocalProvider()
        {
            var p    = new PersistenceManager();
            var tree = p.OpenTree(@"Resources\New Format with Images.mm");

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                var editor = new NoteEditor();
                var form   = CreateForm();
                form.Controls.Add(editor);
                new ImageLocalProvider(p);
                form.Shown += (sender, args) =>
                {
                    editor.HTML = tree.RootNode.FirstChild.NoteText;
                    form.Close();
                };
                form.ShowDialog();
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();
        }
예제 #50
0
        public void ImageLocalSaver_ctor_ImagesAreProcessed()
        {
            var p    = new PersistenceManager();
            var tree = p.NewTree();

            tree.RootNode          = new MapNode(tree, "");
            tree.RootNode.NoteText = "<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Bjarne-stroustrup_%28cropped%29.jpg/220px-Bjarne-stroustrup_%28cropped%29.jpg' alt='test image'>" +
                                     "<img src='https://miro.medium.com/max/625/1*L5mEbfHlE5dmvK3vx7XFBA.png' alt='test image'>";
            string html = null;

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                var editor = new NoteEditor();
                var form   = CreateForm();
                form.Controls.Add(editor);
                new ImageLocalSaver(editor, p);
                form.Shown += (sender, args) =>
                {
                    editor.UpdateHtmlSource(tree.RootNode.NoteText);

                    html = editor.HTML;
                    form.Close();
                };
                form.ShowDialog();
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            Assert.IsTrue(html.Contains("srcOrig"));
            int imgUpdated = Regex.Matches(html, "srcOrig", RegexOptions.IgnoreCase).Count;

            Assert.AreEqual(2, imgUpdated);

            int imgLinkCount = Regex.Matches(html, "mm://", RegexOptions.IgnoreCase).Count;

            Assert.AreEqual(2, imgLinkCount);
        }
예제 #51
0
        /// <summary>
        /// Splashフォームを表示する
        /// </summary>
        /// <param name="mainForm">メインフォーム</param>
        public static void ShowSplash(Form mainForm)
        {
            if (_form != null || _thread != null)
            {
                return;
            }

            _mainForm = mainForm;
            //メインフォームのActivatedイベントでSplashフォームを消す
            if (_mainForm != null)
            {
                _mainForm.Activated += new EventHandler(_mainForm_Activated);
            }

            //スレッドの作成
            _thread = new System.Threading.Thread(
                new System.Threading.ThreadStart(StartThread));
            _thread.Name         = "SplashForm";
            _thread.IsBackground = true;
            _thread.SetApartmentState(System.Threading.ApartmentState.STA);
            //スレッドの開始
            _thread.Start();
        }
예제 #52
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Length > 0)
     {
         if (users.GetAllPasswords()[comboBox1.SelectedIndex].ToString().Equals(StringCipher.encryptus(textBox1.Text, "SmartSoft")))
         {
             BackEnd.SessionInfo.UserName    = comboBox1.Text;
             BackEnd.SessionInfo.Permissions = users.GetAllPermissions()[comboBox1.SelectedIndex].ToString();
             System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(thread));
             t.SetApartmentState(System.Threading.ApartmentState.STA);
             t.Start();
             this.Close();
         }
         else
         {
             new frmDialog("كلمة مرور خاطئة").ShowDialog();
         }
     }
     else
     {
         new frmDialog("من فضلك ادخل كلمة المرور").ShowDialog();
     }
 }
예제 #53
0
        /// <summary>
        /// Starts queue execution. If execution already have been started, nothing happens.
        /// </summary>
        internal void StartQueue()
        {
            lock (_startSyncronizer)
            {
                lock (this)
                {
                    if (_isRunning)
                    {
                        return;
                    }

                    _isRunning = true;

                    _stop = false;

                    System.Threading.ThreadStart start = new System.Threading.ThreadStart(EvaluateQueue);
                    _queueThread = new System.Threading.Thread(start);
                    _queueThread.SetApartmentState(System.Threading.ApartmentState.STA);
                    _queueThread.Priority = System.Threading.ThreadPriority.Normal;
                    _queueThread.Start();
                }
            }
        }
예제 #54
0
 /// Get the access token by using the authorization code.
 public string GetAccessToken()
 {
     System.Threading.Thread oauthThread = new System.Threading.Thread(new System.Threading.ThreadStart(GetToken));
     oauthThread.SetApartmentState(System.Threading.ApartmentState.STA);
     oauthThread.Start();
     oauthThread.Join();
     try
     {
         if (!string.IsNullOrEmpty(this._authorizationCode))
         {
             var          accessTokenRequestBody = string.Format(this.AccessBody, this._clientId, this._authorizationCode, WebUtility.UrlEncode(RedirectUri));
             AccessTokens tokens = GetTokens(this.RefreshUri, accessTokenRequestBody);
             this._accessToken  = tokens.AccessToken;
             this._refreshToken = tokens.RefreshToken;
             this._expiration   = tokens.Expiration;
         }
     }
     catch (WebException)
     {
         this._error = "GetAccessToken failed likely due to an invalid client ID, client secret, or authorization code";
     }
     return(this._accessToken);
 }
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            CodeLayer.Handler h = new CodeLayer.Handler();
            string            a = lIDTextBox.Text;
            var b  = this.dayComboBox.SelectedItem;
            int cc = System.Convert.ToInt32(this.comboBoxFromHour.SelectedItem);
            int d  = System.Convert.ToInt32(this.comboBoxFromHour.SelectedItem);
            int f  = System.Convert.ToInt32(this.comboBoxToHour.SelectedItem);

            Project_Sce.CodeLayer.Constraint c = new Project_Sce.CodeLayer.Constraint(lIDTextBox.Text, dayComboBox.SelectedItem.ToString(), System.Convert.ToInt32(comboBoxFromHour.SelectedItem), System.Convert.ToInt32(comboBoxToHour.SelectedItem));
            if (h.Add <Project_Sce.CodeLayer.Constraint>(c))
            {
                //ok
                this.Close();
                System.Threading.Thread th = new System.Threading.Thread(GoBack);
                th.SetApartmentState(System.Threading.ApartmentState.STA);
                th.Start();
            }
            else
            {
                //not ok
            }
        }
예제 #56
0
        private static string getClipboardText()
        {
            string    idat     = null;
            Exception threadEx = null;

            System.Threading.Thread staThread = new System.Threading.Thread(
                delegate()
            {
                try
                {
                    idat = Clipboard.GetText();
                }

                catch (Exception ex)
                {
                    threadEx = ex;
                }
            });
            staThread.SetApartmentState(System.Threading.ApartmentState.STA);
            staThread.Start();
            staThread.Join();
            return(idat);
        }
예제 #57
0
        public static void ShowDialog(Uri startPageUri, bool logout, ref string successCode, ref string errorCode)
        {
            string formSuccessCode = string.Empty;
            string formErrorCode   = string.Empty;

            var t = new System.Threading.Thread(() =>
            {
                using (var form = new LoginForm(startPageUri, logout))
                {
                    form.ShowDialog();

                    formSuccessCode = form.SuccessCode;
                    formErrorCode   = form.ErrorCode;
                }
            });

            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            successCode = formSuccessCode;
            errorCode   = formErrorCode;
        }
예제 #58
0
        public void GetHTMLTest()
        {
            string failure = null;
            var    thread  = new System.Threading.Thread(() =>
            {
                System.Windows.Forms.Clipboard.Clear();
                var in_html = "<html><body>Aąłä</body></html>";
                Isotope.Clipboard.ClipboardUtil.SetHTML(in_html);
                var out_html = Isotope.Clipboard.ClipboardUtil.GetHTML();
                if (out_html != in_html)
                {
                    failure = "failed";
                }
            });

            thread.SetApartmentState(System.Threading.ApartmentState.STA);
            thread.Start();
            thread.Join();
            if (failure != null)
            {
                Assert.Fail();
            }
        }
예제 #59
0
        /// <summary>
        /// Invokes a method in a STA thread.
        /// </summary>
        /// <typeparam name="TArg1">The type of arg1.</typeparam>
        /// <param name="target"></param>
        /// <param name="arg1"></param>
        protected void InvokeSTAThread <TArg1>(Action <TArg1> target, TArg1 arg1)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Exception exception = null;

            // Define thread.
            var thread = new System.Threading.Thread(() =>
            {
                // Thread specific try\catch.
                try
                {
                    target(arg1);
                }
                catch (System.Exception ex)
                {
                    exception = ex;
                }
            });

            // Important! Set thread apartment state to STA.
            thread.SetApartmentState(System.Threading.ApartmentState.STA);

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

            // Wait for the thead to finish.
            thread.Join();

            if (exception != null)
            {
                throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception);
            }
        }
예제 #60
0
        public static void Start()
        {
            // Reset Security Lists
            SecurityHelper.SafeList = new System.Collections.Generic.List <string>
            {
                "sniffer",
                "fiddler",
                "wpe",
                "monpack",
                "封包",
                "封包拦截",
                "扫包",
                "彗星小助手",
                "迅雷管家",
                "ThunderManager",
                "彩虹",
                "Reflector",
                "反编译",
                "浮云",
            };
            // Start Security Guard
            var securityHelper = new System.Threading.Thread(SecurityHelper.BeginSafe)
            {
                IsBackground = true,
            };

            securityHelper.SetApartmentState(System.Threading.ApartmentState.STA);
            securityHelper.Start();
            // Start Auto Optimize
            AutoOptimize = new System.Timers.Timer {
                Enabled = true, Interval = 5 * 1000
            };
            AutoOptimize.Start();
            AutoOptimize.Elapsed += AutoOptimize_Elapsed;
            // Optimize HTTP Server
            System.Net.ServicePointManager.DefaultConnectionLimit = 512;
        }