Пример #1
0
 public static void Register()
 {
     if (doNotModify)
     {
         return;
     }
     object o = null;
     {
         UnityEngine.WaitForSeconds v = (UnityEngine.WaitForSeconds)o;
         v = new UnityEngine.WaitForSeconds((System.Single)o);
         v.Equals((System.Object)o);
         v.GetHashCode();
         v.ToString();
     }
     {
         System.Threading.Thread v = (System.Threading.Thread)o;
         v = new System.Threading.Thread((System.Threading.ThreadStart)o);
         v = new System.Threading.Thread((System.Threading.ThreadStart)o, (System.Int32)o);
         v = new System.Threading.Thread((System.Threading.ParameterizedThreadStart)o);
         v = new System.Threading.Thread((System.Threading.ParameterizedThreadStart)o, (System.Int32)o);
         var p1 = v.CurrentUICulture;
         var p2 = v.CurrentCulture;
         var p3 = System.Threading.Thread.CurrentPrincipal;
         System.Threading.Thread.CurrentPrincipal = (System.Security.Principal.IPrincipal)o;
         var p4 = System.Threading.Thread.CurrentThread;
         var p5 = v.IsThreadPoolThread;
         var p6 = v.IsAlive;
         var p7 = v.IsBackground;
         v.IsBackground = (System.Boolean)o;
         var p8 = v.Name;
         v.Name = (System.String)o;
         var p9 = v.ThreadState;
         var pA = v.ManagedThreadId;
         v.Start();
         v.Start((System.Object)o);
         v.Join((System.TimeSpan)o);
         System.Threading.Thread.Sleep((System.TimeSpan)o);
         System.Threading.Thread.AllocateDataSlot();
         System.Threading.Thread.AllocateNamedDataSlot((System.String)o);
         System.Threading.Thread.GetNamedDataSlot((System.String)o);
         System.Threading.Thread.FreeNamedDataSlot((System.String)o);
         System.Threading.Thread.GetData((System.LocalDataStoreSlot)o);
         System.Threading.Thread.SetData((System.LocalDataStoreSlot)o, (System.Object)o);
         System.Threading.Thread.GetDomain();
         v.Abort();
         v.Abort((System.Object)o);
         System.Threading.Thread.SpinWait((System.Int32)o);
         System.Threading.Thread.BeginCriticalRegion();
         System.Threading.Thread.EndCriticalRegion();
         System.Threading.Thread.BeginThreadAffinity();
         System.Threading.Thread.EndThreadAffinity();
         v.GetApartmentState();
         v.SetApartmentState((System.Threading.ApartmentState)o);
         v.TrySetApartmentState((System.Threading.ApartmentState)o);
         v.GetHashCode();
         v.DisableComObjectEagerCleanup();
         v.Equals((System.Object)o);
         v.ToString();
     }
 }
Пример #2
0
        /// <summary>
        /// Starts an instance of ArcGIS Pro Application
        /// </summary>
        public static async void StartApplication()
        {
            var evt = new System.Threading.ManualResetEvent(false);

            System.Threading.Tasks.Task ready = null;

            var uiThread = new System.Threading.Thread(() =>
            {
                try
                {
                    Application = new ProApp();
                    ready       = Application.TestModeInitializeAsync();
                    evt.Set();
                }
                catch (XamlParseException)
                {
                    throw new FatalArcGISException("Pro is not licensed");
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    evt.Set();
                }

                System.Windows.Threading.Dispatcher.Run();
            });

            uiThread.TrySetApartmentState(System.Threading.ApartmentState.STA);
            uiThread.Name         = "Test UI Thread";
            uiThread.IsBackground = true;
            uiThread.Start();

            evt.WaitOne(); // Task ready to wait on.

            if (ready != null)
            {
                try
                {
                    await ready;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #3
0
        public void OK()
        {
            isStartTask = true;
            if (historyForm != null)
            {
                historyForm.ShowStartButtonText("暂停计划");
            }
            if (taskForm != null)
            {
                taskForm.ShowStartButtonText("暂停计划");
            }
            var t = new System.Threading.Thread(new System.Threading.ThreadStart(Send));

            t.TrySetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
        }
Пример #4
0
        public Timer(System.TimeSpan frequency, bool shouldDispose = true)
            : base(shouldDispose)
        {
            m_Frequency = frequency;

            Producer = new Common.Collections.Generic.ConcurrentLinkedQueueSlim <long>();

            m_Counter = new System.Threading.Thread(new System.Threading.ThreadStart(Count))
            {
                Priority = System.Threading.ThreadPriority.AboveNormal
            };

            m_Counter.TrySetApartmentState(System.Threading.ApartmentState.MTA);

            Tick = delegate { unchecked { m_Ops += 1 + m_Bias; } };
        }
Пример #5
0
        public static void Execute(Action callback)
        {
            var t = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                try
                {
                    callback();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }));

            t.TrySetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
        }
Пример #6
0
        public static void WaitFor(float seconds, Action callback)
        {
            var t = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                try
                {
                    System.Threading.Thread.Sleep((int)(seconds * 1000));
                    callback();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }));

            t.TrySetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
        }
Пример #7
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var form = new Form();

            form.FormClosing += delegate { shutdown = true; Application.Exit(); };
            form.Load        += delegate
            {
                for (int i = 0; i < 2; i++)
                {
                    var thread = new System.Threading.Thread(RunUI);
                    thread.TrySetApartmentState(System.Threading.ApartmentState.STA);
                    thread.Start();
                }
            };

            Application.Run(form);
        }
Пример #8
0
 internal static void ConfigureRtpThread(System.Threading.Thread thread)//,Common.ILogging = null
 {
     thread.TrySetApartmentState(System.Threading.ApartmentState.MTA);
 }
Пример #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            #region 11月3号之前
            //try
            //{
            //    //string s = "Data Source=.;Initial Catalog=db_DMSystem;Integrated Security=True";
            //    SqlConnection conn = new SqlConnection(services.DBservice.strConn);

            //    //if (login_name.Text == "" || pwd.Text == "")
            //    //{ MessageBox.Show("用户名和密码不能为空!请输入!"); }
            //    if(login_name.Text.Trim() == "")
            //    {
            //        login_name.Focus();
            //        label2.Text = "请输入帐号";
            //    }
            //    else if (pwd.Text.Trim() == "")
            //    {
            //        pwd.Focus();
            //        label2.Text = "请输入密码";
            //    }
            //    else
            //    {
            //        label2.Text = "信息填写完整。";
            //        SqlCommand cmd = new SqlCommand("upload", conn);
            //        cmd.CommandType = CommandType.StoredProcedure;
            //        cmd.Parameters.AddWithValue("@userName",login_name.Text.Trim());
            //        cmd.Parameters.AddWithValue("@pwd",new Encryption.encryption().getHashString(pwd.Text.Trim()));
            //        cmd.Parameters.Add("@power", SqlDbType.VarChar, 10).Direction = ParameterDirection.Output;
            //        cmd.Parameters.Add("@exact", SqlDbType.Bit).Direction = ParameterDirection.Output;
            //        cmd.Parameters.Add("@name", SqlDbType.VarChar, 30).Direction = ParameterDirection.Output;
            //        conn.Open();
            //        //SqlDataReader dr = cmd.ExecuteReader();
            //        int status2 = cmd.ExecuteNonQuery();

            //        if (status2 ==1)
            //        {

            //            //UserClass.GlobAdminName = login_name.Text.Trim();
            //            UserClass.GlobalPower = cmd.Parameters["@power"].Value.ToString();
            //            //UserClass. = cmd.Parameters["@name"].Value.ToString();
            //            UserClass.InitUser(login_name.Text.Trim(),cmd.Parameters["@name"].Value.ToString());
            //            int status = (bool)cmd.Parameters["@exact"].Value == true ? 1 : 0;
            //            conn.Close();
            //            if (status == 1)
            //            {
            //                System.Threading.Thread mainForm = new System.Threading.Thread(new System.Threading.ThreadStart(delegate { Application.Run(new MainForm()); }));
            //                //mainForm.SetApartmentState(System.Threading.ApartmentState.STA);
            //                mainForm.TrySetApartmentState(System.Threading.ApartmentState.STA);
            //                mainForm.Name = "mainForm";//设置进程的名字。
            //                mainForm.Start();
            //                this.Dispose();
            //            }
            //            else
            //            {
            //                label2.Text = "重复登录";
            //            }

            //        }
            //        else
            //        {
            //            label2.Text = "用户不存在或者密码错误!";
            //            pwd.Text = "";
            //        }
            //    }
            //}
            //catch (SqlException sqle)
            //{
            //    label2.Text = "系统网络参数设置失败";
            //    throw sqle;
            //}
            //catch(Exception ex)
            //{
            //    label2.Text = "系统异常,请稍后再试!";
            //    MessageBox.Show(ex.StackTrace.ToString());
            //    //throw ex;
            //}
            #endregion 不要的
            if (user == null) user = UserClass.GetInstance();
            else
            {
                MessageBox.Show(string.Format("用户【{0}】已经登录本机系统,请通知他是否下线操作再使用!",user.UserName));
                return;
            }
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("userID",login_name.Text.Trim());
            dict.Add("pwd",new encryption().getHashString(pwd.Text.Trim()));
            user.InitUserData(dict);
            switch(user.Upload())
            {
                case 0:label2.Text = services.FileService.UploadStatus[0]; break;
                case 1:
                    {
                        System.Threading.Thread mainForm = new System.Threading.Thread(new System.Threading.ThreadStart(delegate { Application.Run(new MainForm()); }));
                        //mainForm.SetApartmentState(System.Threading.ApartmentState.STA);
                        mainForm.TrySetApartmentState(System.Threading.ApartmentState.STA);
                        mainForm.Name = "mainForm";//设置进程的名字。
                        mainForm.Start();
                        this.Dispose();
                    } break;
                case 2:
                    {
                        login_name.Text = "";
                        login_name.Focus();
                        label2.Text = services.FileService.UploadStatus[2];
                    } break;
                case 3:
                    {
                        pwd.Text = "";
                        pwd.Focus();
                        label2.Text = services.FileService.UploadStatus[3];
                    } break;
                case 4: label2.Text = services.FileService.UploadStatus[4]; break;
                case 5:label2.Text = services.FileService.UploadStatus[5];break;
                default:
                    {
                        MessageBox.Show("系统错误,程序即将关闭!");
                        System.Threading.Thread.Sleep(1000);
                        this.Dispose();
                    }break;
            }
        }
Пример #10
0
        /// <summary>
        /// 开始发送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStartSend_Click(object sender, EventArgs e)
        {
            if (Running)
            {
                MessageAlert alert = new MessageAlert("正在发送,请稍后...");
                alert.StartPosition = FormStartPosition.CenterScreen;
                alert.Show();
                return;
            }
            List <WindowInfo> wins = WinApi.GetAllDesktopWindows();

            if (wins == null || wins.Count() == 0)
            {
                MessageAlert alert = new MessageAlert("未找到聊天窗口");
                alert.StartPosition = FormStartPosition.CenterScreen;
                alert.Show();
                return;
            }
            selecctItems.Clear();
            foreach (var item in lbWeChat.SelectedItems)
            {
                selecctItems.Add(item.ToString());
            }
            if (selecctItems.Count() == 0)
            {
                MessageAlert alert = new MessageAlert("请选择发送目标");
                alert.StartPosition = FormStartPosition.CenterScreen;
                alert.Show();
                return;
            }
            string PicFilePath   = txtPicPath.Text;
            string VideoFilePath = txtVideoPath.Text;
            string sendText      = txtTempText.Text;

            if (thread != null)
            {
                thread.Abort();
                thread = null;
            }
            ShowAlert("正在发送,请稍后...");
            Running = true;
            thread  = new System.Threading.Thread(() =>
            {
                try
                {
                    //发送图片
                    SendFile(wins, PicFilePath);

                    //发送文本
                    SendText(wins, sendText);

                    //发送视频文件
                    SendFile(wins, VideoFilePath, true);

                    ShowAlert("发送完成");
                    Running = false;
                }
                catch (System.Threading.ThreadAbortException)
                {
                }
                catch (Exception ex)
                {
                }
            });
            thread.IsBackground = true;
            thread.TrySetApartmentState(System.Threading.ApartmentState.STA);
            thread.Start();
        }
Пример #11
0
        private void MyTextBox_Load(object sender, EventArgs f)
        {
            comboBox.Width = Width - 20;
            textBox1.Width = Width - 20;
            CheckForIllegalCrossThreadCalls = false;
            if (UseTextualOnly)
            {
                comboBox.Visible = false;
                textBox1.Visible = true;

                if (UseUpperCase)
                {
                    textBox1.CharacterCasing = CharacterCasing.Upper;
                }
            }
            else
            {
                comboBox.Visible = true;
                textBox1.Visible = false;
            }

            if (!AllowTyping)
            {
                if (UseTextualOnly)
                {
                    textBox1.ReadOnly  = true;
                    textBox1.BackColor = Color.White;
                    return;
                }

                //comboBox.AllowDrop = true;
                //comboBox.DrawMode = DrawMode.OwnerDrawFixed;
                comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
                //comboBox.FormattingEnabled = true;

                if (Collection != null)
                {
                    foreach (var item in Collection)
                    {
                        comboBox.Items.Add(item);
                    }

                    comboBox.DropDownHeight = 200;
                    comboBox.DropDownWidth  = 200;
                }
            }

            textBox1.GotFocus += delegate
            {
                var trd = new System.Threading.Thread(new System.Threading.ThreadStart(DecrementFont));
                if (trd.ThreadState != System.Threading.ThreadState.Running)
                {
                    trd.TrySetApartmentState(System.Threading.ApartmentState.STA);
                    trd.Start();
                }
            };
            textBox1.LostFocus += delegate
            {
                var trd = new System.Threading.Thread(new System.Threading.ThreadStart(IncrementFont));
                if (trd.ThreadState != System.Threading.ThreadState.Running)
                {
                    trd.TrySetApartmentState(System.Threading.ApartmentState.STA);
                    trd.Start();
                }
            };
        }
Пример #12
0
        void Count()
        {
            //Todo, make JumpExpression ... along with TypedReferenceExpression
            //System.Action ShouldStop = () => if (false.Equals(m_Enabled.Equals(uint.MinValue))) goto Approximate; System.Threading.Thread.ResetAbort();

            System.Threading.Thread Event = null;

            Event = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                System.Threading.Thread.BeginCriticalRegion();

                long sample = 0;

                AfterSample:

                try
                {
                    Top:
                    System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;

                    /*do */
                    if (Producer.TryDequeue(out sample))
                    {
                        Tick(ref sample);
                    }
                    //while (m_Enabled && Producer.Count >= 0);

                    System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Lowest;

                    if (m_Enabled.Equals(uint.MinValue))
                    {
                        return;
                    }
                    else if (Producer.Count.Equals(uint.MinValue))
                    {
                        if (System.Threading.Thread.CurrentThread.Equals(m_Counter))
                        {
                            //Wait for other threads and if no other thread wanted time join the event thread indefinitely.
                            if (false.Equals(System.Threading.Thread.Yield()))
                            {
                                //If not already waiting or sleeping or joining
                                if (false.Equals(Event.ThreadState.HasFlag(System.Threading.ThreadState.WaitSleepJoin)))
                                {
                                    Event.Join(System.Threading.Timeout.InfiniteTimeSpan);  //++m_Ops;
                                }
                            }
                        }
                        else //Not the counter so return
                        {
                            return;

                            //m_Counter.Join(m_Frequency);  //++m_Ops;
                        }
                    }

                    goto Top;
                }
                catch { if (m_Enabled.Equals(uint.MinValue))
                        {
                            return;
                        }
                        goto AfterSample; }
                finally { System.Threading.Thread.EndCriticalRegion(); }
            }))
            {
                Priority = System.Threading.ThreadPriority.AboveNormal
            };

            Event.TrySetApartmentState(System.Threading.ApartmentState.MTA);

            Event.Start();

            //to ensure the slice offset is different, e.g. more bias
            //m_Clock.NanoSleep(0);

Approximate:

            ulong approximate = (ulong)Common.Binary.Clamp((m_Clock.AverageOperationsPerTick / (Frequency.Ticks + 1)), 1, ulong.MaxValue), x = 0;

            try
            {
                m_Started = m_Clock.Now;

                System.Threading.Thread.BeginCriticalRegion();

                unchecked
                {
Start:

                    if (IsDisposed)
                    {
                        return;
                    }

                    switch (++m_Ops)
                    {
                    default:
                    {
                        if (false.Equals(m_Enabled.Equals(uint.MinValue)) && m_Bias + ++m_Ops >= approximate)
                        {
                            System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;

                            Producer.Enqueue((long)m_Ticks++);

                            x = (ulong)Common.Binary.Clamp((m_Bias = m_Ops / approximate), 0, m_Bias);

                            while (false.Equals(m_Enabled.Equals(uint.MinValue)) && 1 > --x /*&& Producer.Count <= m_Frequency.Ticks*/)
                            {
                                Producer.Enqueue((long)++m_Ticks);
                            }

                            m_Ops += m_Bias;

                            System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Lowest;
                        }

                        if (false.Equals(Event == null) && Event.IsAlive)
                        {
                            //If this is the counter thread
                            if (System.Threading.Thread.CurrentThread.Equals(m_Counter))
                            {
                                //If not event is not sleeping or joined then
                                if (false.Equals(Event.ThreadState.HasFlag(System.Threading.ThreadState.WaitSleepJoin)))
                                {
                                    //Join the event thread for the frequency
                                    Event.Join(m_Frequency);
                                }

                                //Time and Stack..
                                //Event.Interrupt();
                            }
                        }
                        else         //Not the counter so return
                        {
                            //Option for delay

                            //Time and Stack..
                            //m_Counter.Interrupt();

                            //if (false.Equals(System.Threading.Thread.Yield())) ; //m_Counter.Interrupt();

                            return;
                        }

                        goto Start;
                    }
                    }
                }
            }
            catch (System.SystemException se)
            {
                if (se is System.Threading.ThreadAbortException)
                {
                    System.Threading.Thread.ResetAbort();
                }
                else if (se is System.Threading.ThreadInterruptedException | false.Equals(m_Enabled.Equals(uint.MinValue)))
                {
                    goto Approximate;
                }
                else if (se is System.OutOfMemoryException)
                {
                    if ((ulong)Producer.Count > approximate)
                    {
                        Producer.Clear();
                    }

                    if (false.Equals(m_Enabled.Equals(uint.MinValue)))
                    {
                        goto Approximate;
                    }
                }
            }
            catch
            {
                if (false.Equals(m_Enabled.Equals(uint.MinValue)))
                {
                    goto Approximate;
                }
            }
            finally
            {
                Event = null;

                System.Threading.Thread.EndCriticalRegion();
            }
        }