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


C# Form.BeginInvoke方法代码示例

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


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

示例1: SetCtrlEnable

 public static void SetCtrlEnable(Form parentForm, Control ctrl, bool value)
 {
     if (parentForm.InvokeRequired)
     {
         SetCtrlEnableHandler method = new SetCtrlEnableHandler(SetCtrlEnableMethod);
         parentForm.BeginInvoke(method, new object[] { ctrl, value });
     }
     else
     {
         SetCtrlEnableMethod(ctrl, value);
     }
 }
开发者ID:ljf1239848066,项目名称:WifiShare,代码行数:12,代码来源:ListBoxLogs.cs

示例2: ExecuteInThread

		private void ExecuteInThread(ThreadStart run)
		{
			Exception uncaughtException = null;
			var thread = new Thread(() =>
			{
				try
				{
					run();
				}
				catch (Exception e)
				{
					uncaughtException = e;
				}

				Application.DoEvents();
				Application.Exit();
			});

			var form = new Form();
			if (form.Handle == IntPtr.Zero)
			{
				throw new InvalidOperationException("Control handle could not be obtained");
			}
			var invoke = form.BeginInvoke((MethodInvoker)thread.Start);

			Application.Run();
			form.EndInvoke(invoke);
			if (uncaughtException != null)
			{
				preserveStackTrace.Invoke(uncaughtException, null);
				throw uncaughtException;
			}
		}
开发者ID:pil0t,项目名称:Castle.Windsor,代码行数:33,代码来源:SynchronizeViaAttributeTestCase.cs

示例3: ShowForm

 public static void ShowForm(Form form, bool show)
 {
     if (form.InvokeRequired)
     {
         form.BeginInvoke(new Action(() =>
         {
             if (show)
             {
                 form.Show();
                 form.BringToFront();
                 form.WindowState = FormWindowState.Normal;
             }
             else
             {
                 form.Hide();
                 form.WindowState = FormWindowState.Minimized;
             }
         }));
     }
     else
     {
         if (show)
         {
             form.Show();
             form.BringToFront();
             form.WindowState = FormWindowState.Normal;
         }
         else
         {
             form.Hide();
             form.WindowState = FormWindowState.Minimized;
         }
     }
 }
开发者ID:peterwillcn,项目名称:Avalon-nano,代码行数:34,代码来源:SafeControlUpdater.cs

示例4: DownloadUpdate

        private static void DownloadUpdate(Form form, UpdateItem updateItem)
        {
            if (form.InvokeRequired)
            {
                form.BeginInvoke(new MethodInvoker(() => DownloadUpdate(form, updateItem)));
                return;
            }

            new UpdaterDownloadWindow(updateItem).ShowDialog(form);
        }
开发者ID:RoDaniel,项目名称:featurehouse,代码行数:10,代码来源:Updater.cs

示例5: AttachForm

        public static void AttachForm(Form form)
        {
            Action<string> handler = msg => form.BeginInvoke((Action)(() =>
            {
                form.Text = msg;
                form.Refresh();
            }));

            MessageSanded += handler;
            form.Closed += (s, e) => MessageSanded -= handler;
        }
开发者ID:poolsar,项目名称:LotCreator,代码行数:11,代码来源:ProccessMesenger.cs

示例6: ChangeComboBoxValue

 public static void ChangeComboBoxValue(Form parentForm, ComboBox ctrl)
 {
     if (parentForm.InvokeRequired)
     {
         ChangeComboBoxValueHandler method = new ChangeComboBoxValueHandler(ChangeComboBoxValueMethod);
         parentForm.BeginInvoke(method, new object[] { ctrl });
     }
     else
     {
         ChangeComboBoxValueMethod(ctrl);
     }
 }
开发者ID:ljf1239848066,项目名称:WifiShare,代码行数:12,代码来源:ListBoxLogs.cs

示例7: AddCtrlValue

 public static void AddCtrlValue(Form parentForm, Control ctrl, string value)
 {
     if (parentForm.InvokeRequired)
     {
         AddCtrlValueHandler method = new AddCtrlValueHandler(AddCtrlValueMethod);
         parentForm.BeginInvoke(method, new object[] { ctrl, value });
     }
     else
     {
         AddCtrlValueMethod(ctrl, value);
     }
 }
开发者ID:ljf1239848066,项目名称:WifiShare,代码行数:12,代码来源:ListBoxLogs.cs

示例8: DoFade

        static void DoFade(Form form, double fromOpacity, double toOpacity, double durationMsec, Action endCallback)
        {
            form.BeginInvoke(new Action(delegate
            {
                Fade(form, fromOpacity, toOpacity, durationMsec);

                if (endCallback != null)
                {
                    endCallback();
                }
            }));
        }
开发者ID:schmich,项目名称:ephemeral,代码行数:12,代码来源:FadeEffect.cs

示例9: SetCtrlTag

 public static void SetCtrlTag(Form parentForm, Control ctrl, string value)
 {
     if (parentForm.InvokeRequired)
     {
         SetCtrlTagHandler method = new SetCtrlTagHandler(SetCtrlTagMethod);
         parentForm.BeginInvoke(method, new object[] { ctrl, value });
     }
     else
     {
         SetCtrlTagMethod(ctrl, value);
     }
 }
开发者ID:ljf1239848066,项目名称:WifiShare,代码行数:12,代码来源:ListBoxLogs.cs

示例10: DanglingWindowMessage

 public void DanglingWindowMessage()
 {
     using (OuterTest nuf = new OuterTest())
     {
         Form f = new Form();
         f.Show();
         System.Threading.EventWaitHandle w = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset);
         System.Threading.ThreadPool.QueueUserWorkItem(delegate(object o)
         {
             f.BeginInvoke(new MethodInvoker(delegate()
             {
                 MessageBox.Show("", "Blah");
             }));
             w.Set();
         });
         w.WaitOne();
         Assert.Throws<FormsTestAssertionException>(() => nuf.Verify());
     }
 }
开发者ID:ChrisPelatari,项目名称:XunitForms,代码行数:19,代码来源:OuterTestTest.cs

示例11: Flash

 public static void Flash(Form form)
 {
     if (form.InvokeRequired)
     {
         form.BeginInvoke(new Action<Form>(WindowFlasher.Flash), new object[]
         {
             form
         });
     }
     else
     {
         InternalFlash(form, FlashFlags.FLASHW_ALL);
         System.Timers.Timer timer = new System.Timers.Timer
         {
             AutoReset = false,
             Interval = 2000.0
         };
         timer.Elapsed += (s, ea) => StopFlash(form);
         timer.Start();
     }
 }
开发者ID:tgmayfield,项目名称:svn-monitor,代码行数:21,代码来源:WindowFlasher.cs

示例12: StopFlash

 public static void StopFlash(Form form)
 {
     try
     {
         if (form.InvokeRequired)
         {
             form.BeginInvoke(new Action<Form>(WindowFlasher.StopFlash), new object[]
             {
                 form
             });
         }
         else
         {
             InternalFlash(form, FlashFlags.FLASHW_STOP);
         }
     }
     catch (Exception ex)
     {
         Logger.Log.Error("Error trying to stop flashing the window.", ex);
     }
 }
开发者ID:tgmayfield,项目名称:svn-monitor,代码行数:21,代码来源:WindowFlasher.cs

示例13: CrawlDate

    private static async Task<Report> CrawlDate(Form ui, Request request)
    {
      var completed = new ManualResetEvent(false);
      Report r = null;

      Action initAction = () =>
      {
        var crawler = new SkyCrawler();
        crawler.Load += async delegate
        {
          r = await crawler.Analyze(request);

          var dates = request.From.ToDateString() + "-" + request.To.ToDateString();
          string path = Path.Combine("e:\\Flights", request.Source + "-" + request.Dectination,
            dates + ".xml");
          Directory.CreateDirectory(Path.GetDirectoryName(path));

          r.ToXml(path);
          crawler.Close();
          completed.Set();

          if (r.Data.Length > 0)
          {
            Console.Out.WriteLine("{0} -> {1}: {2}", dates, request.Dectination, r.Data[0].Price);
          }
        };
        crawler.Show();
      };

      await Task.Factory.FromAsync(
        ui.BeginInvoke(initAction),
        x => { ui.EndInvoke(x);  });

      return await Task.Factory.StartNew(() =>
      {
        completed.WaitOne();
        return r;
      });      
    }
开发者ID:jonnyzzz,项目名称:utils,代码行数:39,代码来源:Program.cs

示例14: Main

    static void Main()
    {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);

      var progressForm = new Form();
      progressForm.Load += async (sender, args) =>
      {
        var enumerable = Tasks().ToArray();
        int c = 0;
        foreach (var request in enumerable)
        {
          c++;
          progressForm.BeginInvoke((Action) (() =>
          {
            progressForm.Name = progressForm.Text = string.Format("{0} of {1}", c, enumerable.Length);
          }));

          await CrawlDate(progressForm, request);
        }
        progressForm.Close();
      };
      Application.Run(progressForm);
    }
开发者ID:jonnyzzz,项目名称:utils,代码行数:24,代码来源:Program.cs

示例15: Play

        public void Play( Form on )
        {
            var screens = Screen.AllScreens;
            var screens_left  = screens.Min( screen => screen.Bounds.Left  );
            var screens_right = screens.Max( screen => screen.Bounds.Right );
            var screens_width = screens_right-screens_left;

            var bestScreen = screens.OrderByDescending( screen => {
                var area = screen.Bounds;
                area.Intersect( on.Bounds );
                return area.Width*area.Height;
            }).First();

            var balances = new[]{1.5f,1.5f};
            if ( screens.Length==3 && DisplayBalances.ContainsKey(bestScreen.DeviceName) ) balances = DisplayBalances[bestScreen.DeviceName];

            var path   = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\.Default\"[email protected]"\.Current").GetValue(null) as string;
            var stream = new WaveStream(path);
            var buffer = new AudioBuffer() { AudioBytes=(int)stream.Length, AudioData=stream, Flags=BufferFlags.EndOfStream };

            var voice = new SourceVoice( XAudio2, stream.Format );
            voice.SubmitSourceBuffer( buffer );
            voice.SetChannelVolumes( balances.Length, balances );
            voice.BufferEnd += (sender,ctx) => {
                try {
                    on.BeginInvoke(new Action(()=>{
                        voice.Dispose();
                        buffer.Dispose();
                        stream.Dispose();
                    }));
                } catch ( InvalidOperationException ) {
                    // herp derp on must be disposed/gone
                }
            };
            voice.Start();
        }
开发者ID:MaulingMonkey,项目名称:uberirc,代码行数:36,代码来源:Sounds.cs


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