//ThreadPool threads are background threads, which do not keep the application running if the main thread ends
        //http://127.0.0.1:47873/help/1-4780/ms.help?method=page&id=41972034-92ED-450A-9664-AB93FCC6F1FB&topicversion=100&topiclocale=EN-US&SQM=1&product=VS&productVersion=100&locale=EN-US
        static void FuncAsync(System.Action f)
        {
            //f.Invoke();
            AsyncCallback cb = FuncAsyncCB;	//new ?
              Object argsOrUserState = null;
            IAsyncResult result = f.BeginInvoke(cb, argsOrUserState);

            //var handle = result.AsyncWaitHandle;
            //handle.WaitOne();
            //f.EndInvoke(result);
            //result.AsyncWaitHandle.Close();		//que si on a attendu avec WaitOne

            //// Poll while simulating work.
            //while (result.IsCompleted == false)
            //{
            //    Thread.Sleep(250);
            //    Console.Write(".");
            //}
        }
Пример #2
0
 public static void writeVectorToFile(MathNet.Numerics.LinearAlgebra.Double.DenseVector vector, string file, System.Windows.Forms.RichTextBox tb1, MainForm frm)
 {
     System.IO.Stream fileStream = new System.IO.FileStream(file, System.IO.FileMode.Create);
     System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fileStream, System.Text.Encoding.Default);
     double[] arr = vector.Values;
     System.IO.TextWriter tr = new System.IO.StreamWriter(file + ".metainfo");
     tr.WriteLine("Items count");
     tr.WriteLine(vector.Count);
     tr.Flush();
     tr.Close();
     int len = arr.Length;
     vector = null;
     int index = 0;
     byte[] bytes = new byte[arr.Length * 8];
     foreach (double item in arr)
     {
         BitConverter.GetBytes(item).CopyTo(bytes, index);
         if (index / 8 / 500D == Math.Round(index / 8 / 500D)) { tb1.BeginInvoke(new MainForm.setProgressDel(frm.addVal), new object[] { (int)index / 8, len, "Записано" }); }
         index += 8;
     }
     bw.Write(bytes);
     bw.Flush();
     tb1.BeginInvoke(new MainForm.setProgressDel(frm.addVal), new object[] { (int)0, len, "" });
     bw.Flush();
     bw.Close();
     fileStream.Close();
 }
Пример #3
0
 protected override void Invalidate(System.Windows.Forms.Control containerControl)
 {
     Rectangle r = m_Rect;
     r.Width++;
     r.Height++;
     if (containerControl.InvokeRequired)
         containerControl.BeginInvoke(new MethodInvoker(delegate { containerControl.Invalidate(r, true); }));
     else
         containerControl.Invalidate(r, true);
 }
 private void ShowTipCore(System.Windows.Forms.Control control, object component, Skybound.VisualTips.VisualTip tip, System.Drawing.Rectangle toolArea, Skybound.VisualTips.VisualTipDisplayOptions options)
 {
     if ((control != null) && control.InvokeRequired)
     {
         object[] objArr = new object[] {
                                          control, 
                                          component, 
                                          tip, 
                                          toolArea, 
                                          options };
         control.BeginInvoke(new Skybound.VisualTips.VisualTipProvider.ShowTipCoreMethod(ShowTipCore), objArr);
         return;
     }
     bool flag = (options & Skybound.VisualTips.VisualTipDisplayOptions.HideOnMouseLeave) == Skybound.VisualTips.VisualTipDisplayOptions.HideOnMouseLeave;
     Skybound.VisualTips.VisualTipWindow visualTipWindow1 = flag ? Skybound.VisualTips.VisualTipProvider.TrackedTipWindow : CurrentTipWindow;
     if (visualTipWindow1 == null)
     {
         if (flag)
         {
             Skybound.VisualTips.VisualTipProvider.TrackedTipWindow = new Skybound.VisualTips.VisualTipWindow();
             visualTipWindow1 = new Skybound.VisualTips.VisualTipWindow();
         }
         else
         {
             Skybound.VisualTips.VisualTipWindow visualTipWindow2 = new Skybound.VisualTips.VisualTipWindow();
             CurrentTipWindow = new Skybound.VisualTips.VisualTipWindow();
             visualTipWindow1 = visualTipWindow2;
         }
     }
     if (visualTipWindow1.DisplayedTip != tip)
     {
         visualTipWindow1.Undisplay();
         Skybound.VisualTips.VisualTipEventArgs visualTipEventArgs = new Skybound.VisualTips.VisualTipEventArgs(tip, component == null ? control : component);
         tip.SetProvider(this);
         Skybound.VisualTips.VisualTipProvider.UpdateTipTarget(tip, visualTipEventArgs.Instance);
         OnTipPopup(visualTipEventArgs);
         if (visualTipEventArgs.Cancel)
         {
             Skybound.VisualTips.VisualTipProvider.PreventDisplayTip = tip;
             return;
         }
         _CurrentTip = tip;
         CurrentControl = control;
         CurrentComponent = component;
         if (flag)
             Skybound.VisualTips.VisualTipTracker.TrackingProvider = this;
         Skybound.VisualTips.VisualTipProvider.WindowStack.Add(visualTipWindow1, control);
         visualTipWindow1.Display(this, tip, toolArea, options);
         return;
     }
     visualTipWindow1.SetToolArea(toolArea, options);
 }
Пример #5
0
		static void ShowMessageInForm(System.Windows.Forms.Form owner_form, string caption, string fmt, params object[] args)
		{
			string msg = string.Format(fmt, args);
			if (owner_form != null)
			{
				owner_form.BeginInvoke(new Action( () => 
						System.Windows.Forms.MessageBox.Show(owner_form, msg, caption)
					));
			}
			else System.Windows.Forms.MessageBox.Show(msg, caption);
		}
Пример #6
0
		static void ShowMessageInForm(System.Windows.Forms.Form owner_form, string msg)
		{
			if (owner_form != null)
			{
				owner_form.BeginInvoke(new Action( () => 
						System.Windows.Forms.MessageBox.Show(owner_form, msg)
					));
			}
			else System.Windows.Forms.MessageBox.Show(msg);
		}
Пример #7
0
 void Disconnect(System.Windows.Forms.Control sender, object[] parameters)
 {
     try
     {
         int pos = 0;
         int cnt;
         object obj = parameters[0];
         if (obj is GXDLMSDeviceCollection)
         {
             cnt = ((GXDLMSDeviceCollection)obj).Count;
             foreach (GXDLMSDevice it in (GXDLMSDeviceCollection)obj)
             {
                 sender.BeginInvoke(new ProgressEventHandler(this.OnProgress), null, "Disconnecting", ++pos, cnt);
                 it.Disconnect();
             }
         }
         else if (obj is GXDLMSDevice)
         {
             sender.BeginInvoke(new ProgressEventHandler(this.OnProgress), null, "Disconnecting", 0, 1);
             ((GXDLMSDevice)obj).Disconnect();
         }
         else if (obj is GXDLMSObjectCollection)
         {
             GXDLMSObjectCollection tmp = obj as GXDLMSObjectCollection;
             GXDLMSDeviceCollection devices = new GXDLMSDeviceCollection();
             foreach (GXDLMSObject it in tmp)
             {
                 GXDLMSDevice dev = it.Parent.Tag as GXDLMSDevice;
                 if (!devices.Contains(dev))
                 {
                     devices.Add(dev);
                 }
             }
             Disconnect(sender, new object[] { devices });
         }
         else
         {
             sender.BeginInvoke(new ProgressEventHandler(this.OnProgress), null, "Disconnecting", 0, 1);
             GXDLMSObject tmp = obj as GXDLMSObject;
             GXDLMSDevice dev = tmp.Parent.Tag as GXDLMSDevice;
             dev.Disconnect();
         }
     }
     catch (ThreadAbortException)
     {
         //User has cancel action. Do nothing.
     }
     catch (Exception Ex)
     {
         GXDLMS.Common.Error.ShowError(sender, Ex);
     }
     finally
     {
         sender.BeginInvoke(new ProgressEventHandler(this.OnProgress), null, "", 1, 1);
     }
 }
Пример #8
0
 public void SetDispatcher(System.Windows.Threading.Dispatcher dispatcher)
 {
     this.BeginInvoke = action => dispatcher.BeginInvoke(action);
 }
Пример #9
0
 public void AssignControlUntilFocusChange(System.Windows.Forms.Control control)
 {
     MethodInvoker method = delegate {
         if (!control.Focus())
         {
             control.Focus();
         }
         control.LostFocus += delegate {
             this.Control = null;
             control.Dispose();
         };
     };
     control.HandleCreated += delegate {
         control.BeginInvoke(method);
     };
     this.Control = control;
 }
Пример #10
0
		private static void BeginInvokeOnPowershellCommand(System.Management.Automation.PowerShell ps, PSDataCollection<object> varsInput, PSInvocationSettings settings, AsyncCallback callback, RunCommandsArguments args)
		{
			PowerShellTraceSource traceSource = PowerShellTraceSourceFactory.GetTraceSource();
			using (traceSource)
			{
				try
				{
					ps.BeginInvoke<object>(varsInput, settings, callback, args);
				}
				catch (Exception exception1)
				{
					Exception exception = exception1;
					bool flag = PSActivity.ProcessException(args, exception);
					if (!flag)
					{
						PSActivity.ReleaseResourcesAndCheckForEnd(ps, args, false, false);
					}
					else
					{
						PSActivity.BeginActionRetry(args);
					}
					traceSource.TraceException(exception);
				}
			}
		}
Пример #11
0
        private void Connect(System.Windows.Threading.Dispatcher Dispatcher)
        {
            if (!string.IsNullOrEmpty(m_Settings.ServerAddress)) {
            Dispatcher.BeginInvoke((System.Action)(() => {
              txtStatus.Text = string.Format("Connecting to {0}:{1}...", m_Settings.ServerAddress, m_Settings.ServerPort);
            }));
            try {
              IPAddress[] addresses = System.Net.Dns.GetHostAddresses(m_Settings.ServerAddress);
              if (addresses.Length > 0) {
            IPAddress ip = addresses[0];
            IPEndPoint ie = new IPEndPoint(ip, m_Settings.ServerPort);

            m_IgnoreDisconnect = true;
            if (m_Mpc.Connected)
              m_Mpc.Connection.Disconnect();
            m_Mpc.Connection = new MpcConnection(ie);
            if (m_MpcIdle.Connected)
              m_MpcIdle.Connection.Disconnect();
            m_MpcIdle.Connection = new MpcConnection(ie);
            m_IgnoreDisconnect = false;
              }
            }
            catch (Exception ex) {
              Dispatcher.BeginInvoke((System.Action)(() => {
            txtStatus.Text = string.Empty;
              }));
            }
              }
        }
Пример #12
0
 private void Load(System.Windows.Threading.Dispatcher dispatcher)
 {
     //async?//await dispatcher.RunAsync(System.Windows.Core.CoreDispatcherPriority.High, () => CustomLoad());
     Action a = new Action(CustomLoad);
     dispatcher.BeginInvoke(a);
 }
Пример #13
0
 protected void DoGenericLoad(System.Windows.Threading.Dispatcher dispatcher, string urlToCall, Action<string> funcToCall)
 {
     var request = (HttpWebRequest)WebRequest.Create(urlToCall);
     AsyncLoading = true;
     request.Accept = "application/json";
     try
     {
         var async = request.BeginGetResponse((result) =>
         {
             try
             {
                 var response = request.EndGetResponse(result);
                 using (var rs = response.GetResponseStream())
                 {
                     using (var sr = new StreamReader(rs))
                     {
                         var text = sr.ReadToEnd();
                         dispatcher.BeginInvoke(() =>
                         {
                             try
                             {
                                 AsyncLoading = false;
                                 funcToCall(text);
                             }
                             catch (Exception exc)
                             {
                                 ShowError(dispatcher, exc);
                             }
                         });
                     }
                 }
             }
             catch (Exception exc)
             {
                 ShowError(dispatcher, exc);
             }
         },
             null);
     }
     catch (Exception exc)
     {
         ShowError(dispatcher, exc);
     }
 }
Пример #14
0
 protected static void ShowError(System.Windows.Threading.Dispatcher dispatcher, Exception exc)
 {
     dispatcher.BeginInvoke(() =>
     {
         MessageBox.Show("Sorry - there was a problem - " + exc.Message);
     });
 }