本文整理汇总了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);
}
}
示例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;
}
}
示例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;
}
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
}));
}
示例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);
}
}
示例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());
}
}
示例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();
}
}
示例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);
}
}
示例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;
});
}
示例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);
}
示例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();
}