/// <summary>
 /// 开启循环并执行主体功能
 /// </summary>
 /// <param name="method"></param>
 /// <param name="secondsInterval">执行间隔时间</param>
 public void StartWhile(
     System.Windows.Forms.MethodInvoker method,
     int secondsInterval)
 {
     #region
     while (true)
     {
         if (!_enableStop ||
             _status == ThreadStatus.Started)
         {
             try
             {
                 if (method != null)
                 {
                     method();
                 }
             }
             catch (Exception e)
             {
                 LogInterface.Write(e.ToString());
             }
         }
         System.Threading.Thread.Sleep(
             TimeSpan.FromSeconds(secondsInterval));
     }
     #endregion
 }
Esempio n. 2
0
        public override bool ValidatePatch()
        {
            bool result = false;

            System.Windows.Forms.MethodInvoker mi = delegate()
            {
                if (!string.IsNullOrEmpty(patch.Filename))
                {
                    OpenFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(patch.Filename);
                    OpenFileDialog.FileName         = System.IO.Path.GetFileName(patch.Filename);
                }

                if (OpenFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        SetFilename(OpenFileDialog.FileName);
                        result = true;
                    }
                    catch
                    {
                        result = false;
                    }
                }
                else
                {
                    result = false;
                }
            };

            mi();

            return(result);
        }
Esempio n. 3
0
 public ThreadBLL()
 {
     this._workerThread = null;
     this._connected = false;
     this._task = null;
     this._runState = RunState.idle;
     this._connString = String.Empty;///////////////////////important
     this.Connection = new SQLiteConnection();
     this.Adapt = new SQLiteDataAdapter();
 }
Esempio n. 4
0
 public ThreadBLL(String connString)
 {
     this._workerThread = null;
     this._connected = false;
     this._task = null;
     this._runState = RunState.idle;
     this._connString = connString;
     this.Connection = new SQLiteConnection();
     this.Adapt = new SQLiteDataAdapter();
 }
Esempio n. 5
0
 public static void CrossThreadControlCall(System.Windows.Forms.Control control, System.Windows.Forms.MethodInvoker method)
 {
     if (control.InvokeRequired)
     {
         control.Invoke(method);
     }
     else
     {
         method.Invoke();
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Applies the security.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="user">The user.</param>
 public static void ApplySecurityOnWinForms(System.Windows.Forms.Control control, IUser user)
 {
     foreach (var tempControl in TraverseWindowsControls(control))
     {
         var securedObjectName = string.Format("{0}.{1}", control.GetType(), tempControl.Name);
         var securityInfo      = SecurityContext.AuthorizationInfos.FirstOrDefault(tempInfo => tempInfo.ObjectName == securedObjectName);
         if ((securityInfo != null))
         {
             System.Windows.Forms.MethodInvoker methodInvoker = () => SetControl(tempControl, securityInfo.RightType);
             control.Invoke(methodInvoker);
         }
     }
 }
Esempio n. 7
0
        void AttachChildren(int[] indices, string[] texts, ItemsControl itemsControl)
        {
            //仮想化対応 50ミリ周期でイベントハンドリングしていないTreeViewItemを監視する
            //初回はすぐに実行されるようにする
            var timer = new System.Windows.Forms.Timer {
                Interval = 1
            };

            int[] next = null;

            System.Windows.Forms.MethodInvoker eventConnection = () =>
            {
                timer.Interval = 50;

                //子要素取得
                var exists = GetTreeChildren(itemsControl, next, out var notExists);
                foreach (var item in exists)
                {
                    string text = HeaderedItemsControlUtility.GetItemText(item.Value);

                    List <int>    nextIndices = new List <int>(indices);
                    List <string> nextTexts   = new List <string>(texts);
                    nextIndices.Add(item.Key);
                    nextTexts.Add(text);
                    EventConnection(item.Value, false, IsTextKey, nextIndices.ToArray(), nextTexts.ToArray());
                }

                //仮想化でまだ存在していない要素があればそれを監視させる
                next = notExists;

                //全てアタッチしたら終了
                if (next.Length == 0)
                {
                    timer?.Stop();
                }
            };

            //タイマ処理
            timer.Tick += (_, __) =>
            {
                try
                {
                    eventConnection();
                }
                catch
                {
                    timer.Stop();
                }
            };
            timer.Start();
        }
Esempio n. 8
0
        private void MainMap_OnTileLoadComplete(long ElapsedMilliseconds)
        {
            System.Windows.Forms.MethodInvoker m = delegate()
            {
                MapLoadBar.Visibility = Visibility.Hidden;
            };

            try
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, m);
            }
            catch
            {
            }
        }
Esempio n. 9
0
        private void MainMap_OnTileLoadStart()
        {
            System.Windows.Forms.MethodInvoker m = delegate()
            {
                MapLoadBar.Visibility = Visibility.Visible;
            };

            try
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, m);
            }
            catch
            {
            }
        }
        // tile loading stops
        void MainMap_OnTileLoadComplete(long ElapsedMilliseconds)
        {
            MainMap.ElapsedMilliseconds = ElapsedMilliseconds;

            System.Windows.Forms.MethodInvoker m = delegate()
            {
                progressBar1.Visibility = Visibility.Hidden;
                groupBox3.Header        = "loading, last in " + MainMap.ElapsedMilliseconds + "ms";
            };

            try
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, m);
            }
            catch
            {
            }
        }
Esempio n. 11
0
        // tile loading stops
        void MainMap_OnTileLoadComplete(long ElapsedMilliseconds)
        {
            MainMap.ElapsedMilliseconds = ElapsedMilliseconds;

            System.Windows.Forms.MethodInvoker m = delegate()
            {
                progressBar1.Visibility = Visibility.Hidden;
                txtStatus_LoadTime.Text = "Betöltve " + MainMap.ElapsedMilliseconds + "ms alatt.";
            };

            try
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, m);
            }
            catch
            {
            }
        }
Esempio n. 12
0
 public static void InvokeIfRequired(this ISynchronizeInvoke obj, System.Windows.Forms.MethodInvoker action)
 {
     if (obj.InvokeRequired)
     {
         var args = new object[0];
         try
         {
             obj.Invoke(action, args);
         }
         catch
         {
             // ignored
         }
     }
     else
     {
         action();
     }
 }
Esempio n. 13
0
        /// <summary>
        /// 线程函数,用于处理调用
        /// </summary>
        private void ThreadFun()
        {
            try
            {
                System.Windows.Forms.MethodInvoker mi = new System.Windows.Forms.MethodInvoker(ShowProgressBar);
                this.Dispatcher.BeginInvoke(mi);
                while (this.myHandle == null)
                {
                    System.Threading.Thread.Sleep(1000); //sleep to show window
                }

                for (int i = 0; i < 100; ++i)
                {
                    System.Threading.Thread.Sleep(100);
                    // 这里直接调用代理
                    this.Dispatcher.Invoke(this.myHandle, new object[] { i });
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 14
0
 private void Invoke(System.Windows.Forms.MethodInvoker method)
 {
     host.invokeTarget.BeginInvoke(method, emptyObjectArray);
 }
Esempio n. 15
0
        void OnProjectItemAdded(object sender, ProjectItemEventArgs e)
        {
            if (e.Project != project)
            {
                return;
            }

            ReferenceProjectItem reference = e.ProjectItem as ReferenceProjectItem;

            if (reference != null)
            {
                if (reference.ItemType == ItemType.COMReference)
                {
                    System.Windows.Forms.MethodInvoker action = delegate {
                        // Compile project to ensure interop library is generated
                        project.Save();                         // project is not yet saved when ItemAdded fires, so save it here
                        TaskService.BuildMessageViewCategory.AppendText("\n${res:MainWindow.CompilerMessages.CreatingCOMInteropAssembly}\n");
                        BuildCallback afterBuildCallback = delegate {
                            lock (callAfterAddComReference) {
                                if (callAfterAddComReference.Count > 0)
                                {
                                    // run next enqueued action
                                    callAfterAddComReference.Dequeue()();
                                }
                                else
                                {
                                    buildingComReference = false;
                                    ParserService.Reparse(project, true, false);
                                }
                            }
                        };
                        BuildEngine.BuildInGui(project, new BuildOptions(BuildTarget.ResolveComReferences, afterBuildCallback));
                    };

                    // enqueue actions when adding multiple COM references so that multiple builds of the same project
                    // are not started parallely
                    lock (callAfterAddComReference) {
                        if (buildingComReference)
                        {
                            callAfterAddComReference.Enqueue(action);
                        }
                        else
                        {
                            buildingComReference = true;
                            action();
                        }
                    }
                }
                else
                {
                    ParserService.Reparse(project, true, false);
                }
            }
            if (e.ProjectItem.ItemType == ItemType.Import)
            {
                UpdateDefaultImports(project.Items);
            }
            else if (e.ProjectItem.ItemType == ItemType.Compile)
            {
                if (System.IO.File.Exists(e.ProjectItem.FileName))
                {
                    ParserService.EnqueueForParsing(e.ProjectItem.FileName);
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Sets the properties that are linked to the view based on the selected node.
        /// </summary>
        private void PropertiesToNode()
        {
            if (Application.Current == null)
            {
                return;
            }

            if (Application.Current.Dispatcher.CheckAccess())
            {
                if (SelectedNode == null ||
                    NodeAttributes == null ||
                    string.IsNullOrEmpty(NodeAttributes.ProjectItemName))
                {
                    return;
                }

                // Take references to avoid chance of change.
                var attrs = NodeAttributes;
                var node  = SelectedNode;
                var doc   = node.OwnerDocument;

                // Check if node types match, and if not create a new node.
                if (attrs.NodeType.ToString().ToLower() != SelectedNode.Name?.ToLower())
                {
                    // Create new node.
                    var newNode = doc.CreateNode(XmlNodeType.Element, attrs.NodeType.ToString().ToLower(), SelectedNode.NamespaceURI);

                    // Move any child nodes over.
                    var futureOrphans = node.ChildNodes.GetEnumerator();
                    while (futureOrphans.MoveNext())
                    {
                        var orphan = futureOrphans.Current as XmlNode;
                        if (orphan == null)
                        {
                            continue;
                        }

                        node.RemoveChild(orphan);
                        newNode.AppendChild(orphan);
                    }

                    // Replace old node in parent.
                    node.ParentNode.ReplaceChild(newNode, node);
                    node = newNode;
                }

                // Set node name.
                ((XmlElement)node).SetAttribute(Strings.Attributes[XmlAttributeName.Name], attrs.ProjectItemName);

                // Set include property.
                ((XmlElement)node).SetAttribute(Strings.Attributes[XmlAttributeName.Include], attrs.Include.ToString().ToLower());

                // Set or remove template id.
                if (!string.IsNullOrEmpty(attrs.TemplateId))
                {
                    ((XmlElement)node).SetAttribute(Strings.Attributes[XmlAttributeName.TemplateId], attrs.TemplateId);
                }
                else if (node.Attributes[Strings.Attributes[XmlAttributeName.TemplateId]]?.Value != null)
                {
                    ((XmlElement)node).RemoveAttribute(Strings.Attributes[XmlAttributeName.TemplateId]);
                }

                // Save new XML file and update selected node.
                doc.Save(CurrentDataFile);
                SelectedNode = node;
            }
            else
            {
                var del = new System.Windows.Forms.MethodInvoker(PropertiesToNode);
                System.Windows.Application.Current.Dispatcher.Invoke(del);
            }
        }
Esempio n. 17
0
 public void Invoke(System.Windows.Forms.MethodInvoker methodInvoker, bool forceUi)
 {
     invoker.Invoke(methodInvoker);
 }
Esempio n. 18
0
        public void RunOnWorker(System.Windows.Forms.MethodInvoker method, bool synchronous)
        {
            if (_task != null) 								// already doing something?
            {
                Thread.Sleep(100);					// give it 100ms to finish...
                if (_task != null) return;				// still not finished - cannot run new task
            }

            WaitForWorker();
            _task = method;
            _workerThread.Interrupt();

            if (synchronous)
            {
                WaitForWorker();
            }
        }
Esempio n. 19
0
        void OnProjectItemAdded(object sender, ProjectItemEventArgs e)
        {
            if (e.Project != project)
            {
                return;
            }

            ReferenceProjectItem reference = e.ProjectItem as ReferenceProjectItem;

            if (reference != null)
            {
                if (reference.ItemType == ItemType.COMReference)
                {
                    System.Windows.Forms.MethodInvoker action = delegate {
                        // Compile project to ensure interop library is generated
                        project.Save();                         // project is not yet saved when ItemAdded fires, so save it here
                        TaskService.BuildMessageViewCategory.AppendText("\n${res:MainWindow.CompilerMessages.CreatingCOMInteropAssembly}\n");
                        BuildCallback callback = delegate {
                            System.Threading.ThreadPool.QueueUserWorkItem(AddReference, reference);
                            lock (callAfterAddComReference) {
                                if (callAfterAddComReference.Count > 0)
                                {
                                    callAfterAddComReference.Dequeue()();
                                }
                                else
                                {
                                    buildingComReference = false;
                                }
                            }
                        };
                        project.StartBuild(new BuildOptions(BuildTarget.ResolveComReferences, callback));
                    };
                    lock (callAfterAddComReference) {
                        if (buildingComReference)
                        {
                            callAfterAddComReference.Enqueue(action);
                        }
                        else
                        {
                            buildingComReference = true;
                            action();
                        }
                    }
                }
                else
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(AddReference, reference);
                }
            }
            if (e.ProjectItem.ItemType == ItemType.Import)
            {
                UpdateDefaultImports(project.Items);
            }
            else if (e.ProjectItem.ItemType == ItemType.Compile)
            {
                if (System.IO.File.Exists(e.ProjectItem.FileName))
                {
                    ParserService.EnqueueForParsing(e.ProjectItem.FileName);
                }
            }
        }
Esempio n. 20
0
 public void BeginAcceptTcpClient(System.Windows.Forms.MethodInvoker streamEstablishedHandler)
 {
     IAsyncResult ar = tcpListener.BeginAcceptTcpClient(new AsyncCallback(this.AcceptTcpClientCallback), streamEstablishedHandler);
     //TcpClient tcpClient = tcpListener.AcceptTcpClient();//blocking call
 }
Esempio n. 21
0
        public void StartWorker()
        {
            do
            {
                // Wait for main thread wake up!
                //Thread.CurrentThread.Suspend();
                try
                {
                    Thread.Sleep(Timeout.Infinite);
                }
                catch (Exception) { }					// the wakeup call, ie Interrupt() will throw an exception
                // If doing nothing, Form thread will close
                if (_task == null) break;
                // On the contrary, do the task
                _task();
                _task = null;

            } while (true);
        }
Esempio n. 22
0
 public static void InvokeIfRequired(this System.ComponentModel.ISynchronizeInvoke obj, System.Windows.Forms.MethodInvoker action)
 {
     if (obj.InvokeRequired)
     {
         var args = new object[0];
         obj.Invoke(action, args);
     }
     else
     {
         action();
     }
 }
Esempio n. 23
0
 public PcapTcpStream(string remoteIpOrHost, ushort remotePort, bool useSSl, int idleTimeoutMilliSeconds, System.Windows.Forms.MethodInvoker streamEstablishedHandler) : this(useSSl, idleTimeoutMilliSeconds)
 {
     this.tcpClient = new TcpClient(remoteIpOrHost, remotePort);
     if (this.tcpClient.Connected)
     {
         this.SetSocketAsConnected();
         //streamEstablishedHandler. .DynamicInvoke();
     }
     else
     {
         this.socketState = TcpSocketState.Closed;
     }
 }
Esempio n. 24
0
 public void Invoke(System.Windows.Forms.MethodInvoker globalSystemWindowsFormsMethodInvoker)
 {
     invoker.Invoke(globalSystemWindowsFormsMethodInvoker);
 }
Esempio n. 25
0
 private void Invoke(System.Windows.Forms.MethodInvoker mi)
 {
     WinFormsServicePort.Post(new FormInvoke(mi));
 }
Esempio n. 26
0
 public static void InvokeIfRequired(this System.Windows.Forms.Control control, System.Windows.Forms.MethodInvoker action)
 {
     if (control.InvokeRequired)
     {
         control.Invoke(action);
     }
     else
     {
         action();
     }
 }