本文整理汇总了C#中System.Action.BeginInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# Action.BeginInvoke方法的具体用法?C# Action.BeginInvoke怎么用?C# Action.BeginInvoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Action
的用法示例。
在下文中一共展示了Action.BeginInvoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunCommand
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
m_doc = doc;
m_window = new Window {Title = "Object ID and Thread ID", Width = 500, Height = 75};
m_label = new Label();
m_window.Content = m_label;
new System.Windows.Interop.WindowInteropHelper(m_window).Owner = Rhino.RhinoApp.MainWindowHandle();
m_window.Show();
// register the rhinoObjectAdded method with the AddRhinoObject event
RhinoDoc.AddRhinoObject += RhinoObjectAdded;
// add a sphere from the main UI thread. All is good
AddSphere(new Point3d(0,0,0));
// add a sphere from a secondary thread. Not good: the rhinoObjectAdded method
// doesn't work well when called from another thread
var add_sphere_delegate = new Action<Point3d>(AddSphere);
add_sphere_delegate.BeginInvoke(new Point3d(0, 10, 0), null, null);
// handle the AddRhinoObject event with rhinoObjectAddedSafe which is
// desgined to work no matter which thread the call is comming from.
RhinoDoc.AddRhinoObject -= RhinoObjectAdded;
RhinoDoc.AddRhinoObject += RhinoObjectAddedSafe;
// try again adding a sphere from a secondary thread. All is good!
add_sphere_delegate.BeginInvoke(new Point3d(0, 20, 0), null, null);
doc.Views.Redraw();
return Result.Success;
}
示例2: RunAsync
public static DataReaderObservableRunner RunAsync(IDbCommand command, IObserver<IDictionary<string, object>> observer)
{
var instance = new DataReaderObservableRunner(command, observer);
var asyncAction = new Action(instance.Run);
asyncAction.BeginInvoke(asyncAction.EndInvoke, null);
return instance;
}
示例3: BeginUpload
public void BeginUpload(Action<FSUploadResultEntity, Exception> uploadCallback, int timeout)
{
UploadCallBack = uploadCallback;
Action<FSUploadEntity> asyncUploadAction = new Action<FSUploadEntity>((fsUpload) =>
{
StorageServer storageServer = TrackerClient.GetStorageServer();
if (storageServer == null)
{
InnerEx = new Exception("FSUploadTransaction.BeginTTSSynth(): Failed to get Storage server address: Please check ths fdfs storage's config and the fdfs tracker is running.");
return;
}
Exception outputCallbackEx = null;
StorageClient.Upload(storageServer, uploadEntity.FileExtName, uploadEntity.FileSize, uploadEntity.FileBuffer, string.Empty, (filePathArray) =>
{
try
{
FilePath = string.Format("{0}/{1}", filePathArray[0], filePathArray[1]); // 0: groupName, 1:fileName
}
catch (Exception ex2)
{
string err = string.Format("FSUploadTransaction.BeginUpload: Exception when executing OutputCallback of StorageClient.Upload(), FileName={0}, storageServer={1}", uploadEntity.FileName, storageServer.IP);
outputCallbackEx = new Exception(err, ex2);
}
});
if(null != outputCallbackEx)
{
InnerEx = outputCallbackEx;
}
});
asyncUploadAction.BeginInvoke(uploadEntity, new AsyncCallback(CallbackForAsyncAction), this);
}
示例4: RunTask
public SchedulerTask RunTask(Func<TaskFactory, SchedulerTask> fn)
{
progressBar1.Value = 0;
label1.Text = richTextBox1.Text = "";
var factory = ProgramContext.Container.Resolve<TaskFactory>();
task = fn(factory);
task.TaskStarted += (t) => { };
task.TaskFinished += (t) => { };
task.ScriptStarted += (t, s) => { };
task.ScriptFinished += (t, s) => { };
task.ScriptCustomEvent += (t, s, o) => { };
task.Progress.Update +=
(p) => this.Invoke(new Action(
() =>
{
label1.Text = p.Message;
progressBar1.Value = p.Completeness;
richTextBox1.Text += p.Message + Environment.NewLine;
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.ScrollToCaret();
}));
var asyncRunner = new Action(
() =>
{
factory.RunTaskUntilFinished(task);
if (OnTaskComplete != null) OnTaskComplete(this, EventArgs.Empty);
});
asyncRunner.BeginInvoke(null, null);
return task;
}
示例5: Main
public static void Main(string[] args)
{
var cooldown = TASK_COOLDOWN;
if (args.Length > 0) {
cooldown = int.Parse (args [0]);
Console.WriteLine ("Cooldown is {0} ms", cooldown);
}
while (true) { // catch ctrl+c
if (Games.Count < Environment.ProcessorCount) {
GameType type;
GetRandomTask (out type);
Console.WriteLine ("Enqueing type " + type);
var action = new Action<GameType> (RunGame);
Games.Enqueue (new GameAction () {
GameType = type,
Delegate = action,
Result = action.BeginInvoke (type, null, null) // run game here
});
} else {
var game = Games.Dequeue ();
Console.WriteLine ("Waiting for {0} to complete", game.GameType);
try {
game.Delegate.EndInvoke (game.Result); // sync here
} catch (Exception ex) {
Console.WriteLine ("Got exception here, okay i guess... " + ex.GetType ());
Console.WriteLine (ex);
}
}
}
}
示例6: DecodeQR
public void DecodeQR(System.Drawing.Image img)
{
textbox.Text = "正在解析";
Action action = new Action(delegate ()
{
string mess = "";
try
{
DllHelper helper = new DllHelper();
System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(img);
string deCodeAss = "ThoughtWorks.QRCode.Codec.QRCodeDecoder.DeCodeImg";
var destring = helper.InvokQR(deCodeAss, new object[] { bmap, Encoding.UTF8 });
mess = destring.ToString();
}
catch (Exception ex)
{
mess = "解析失败,请重试";
}
Dispatcher.BeginInvoke(new Action(delegate ()
{
textbox.Text = mess;
}), null);
});
action.BeginInvoke(null, null);
}
示例7: BeginStreaming
public void BeginStreaming()
{
try
{
request = new CampfireRequest(this.site)
.CreateRequest(this.site.ApiUrlBuilder.Stream(this.room.ID), HttpMethod.GET);
request.Timeout = -1;
// yes, this is needed. regular authentication using the Credentials property does not work for streaming
string token = string.Format("{0}:X", this.site.ApiToken);
string encoding = Convert.ToBase64String(Encoding.UTF8.GetBytes(token));
request.Headers.Add("Authorization", "Basic " + encoding);
response = request.GetResponse();
responseStream = response.GetResponseStream();
reader = new StreamReader(responseStream, Encoding.UTF8);
del = new Action(() =>
{
ReadNextMessage(reader);
});
del.BeginInvoke(LineRead, null);
}
catch
{
Thread.Sleep(2500);
BeginStreaming();
}
}
示例8: CalculateSize
public void CalculateSize()
{
_calculateAsync = () => {
Size = DirSize(Path);
};
_calculateAsync.BeginInvoke(_calculateAsync.EndInvoke, null);
}
示例9: BeginProcessRequest
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
{
culture = Thread.CurrentThread.CurrentCulture;
principal = Thread.CurrentPrincipal;
processRequest = ProcessRequest;
return processRequest.BeginInvoke(context, cb, extraData);
}
示例10: DownloadButton_Click
private void DownloadButton_Click(object sender, EventArgs e)
{
DownloadButton.Enabled = false;
ChangesTextBox.AppendText(Environment.NewLine);
ChangesTextBox.AppendText("Downloading..." + Environment.NewLine);
var downloadAction = new Action(() =>
{
Parallel.ForEach(m_newPatches, patch =>
{
var localPath = PatchManager.GetPatchFilePath(m_definition, patch.Name);
var directory = PatchManager.GetPatchDirectoryPath(m_definition);
Paths.EnsureDirectoryExists(directory);
GitHubApi.DownloadFile(patch.DownloadUrl, localPath);
this.UpdateUI(() => ChangesTextBox.AppendText(patch.Name + " done." + Environment.NewLine));
});
this.UpdateUI(() =>
{
DialogResult = DialogResult.OK;
});
});
downloadAction.BeginInvoke(null, null);
}
示例11: plotButton_click
private void plotButton_click(object sender, RoutedEventArgs e)
{
if (graphBitmap == null)
{
graphBitmap = new WriteableBitmap(pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Gray8, null);
}
Action doPlotButtonWorkAction = new Action(doPlotButtonWork);
doPlotButtonWorkAction.BeginInvoke(null, null);
#region 注释掉的内容
//int byetePerPixel = (graphBitmap.Format.BitsPerPixel + 7) / 8;
//int stride = byetePerPixel * graphBitmap.PixelWidth;
//int dataSize = stride * graphBitmap.PixelHeight;
//byte[] data = new byte[dataSize];
//Stopwatch watch = new Stopwatch();
////generateGraphData(data);
////新建线程
//Task first = Task.Factory.StartNew(()=>generateGraphData(data,0,pixelWidth/8));
//Task second = Task.Factory.StartNew(() => generateGraphData(data, pixelWidth / 8, pixelWidth / 4));
//Task first1 = Task.Factory.StartNew(() => generateGraphData(data, pixelWidth / 4, pixelWidth / 2));
//Task second1 = Task.Factory.StartNew(() => generateGraphData(data, pixelWidth / 2, pixelWidth));
//Task.WaitAll(first, second,first1,second1);
//duration.Content = string.Format("Duration (ms):{0}", watch.ElapsedMilliseconds);
//graphBitmap.WritePixels(new Int32Rect(0, 0, graphBitmap.PixelWidth, graphBitmap.PixelHeight), data, stride, 0);
//graphImage.Source = graphBitmap;
#endregion
}
示例12: Main
/* expected exit code: 255 */
static void Main (string[] args)
{
if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
AppDomain.CurrentDomain.UnhandledException += (s, e) => {};
ManualResetEvent mre = new ManualResetEvent (false);
var a = new Action (() => { try { throw new CustomException (); } finally { mre.Set (); } });
var ares = a.BeginInvoke (null, null);
if (!mre.WaitOne (5000))
Environment.Exit (2);
try {
a.EndInvoke (ares);
Environment.Exit (4);
} catch (CustomException) {
/* expected behaviour */
Environment.Exit (255);
} catch (Exception ex) {
Console.WriteLine (ex);
Environment.Exit (3);
}
Environment.Exit (5);
}
示例13: CalculateTwoSums
private void CalculateTwoSums(int lowerBound, int upperBound)
{
for (int currentSum = lowerBound; currentSum <= upperBound; currentSum++)
{
Action twoSum = new Action(() =>
{
foreach (long value in this.hashTable.Values)
{
if (!distinctSums.ContainsKey(currentSum))
{
long searchValue = currentSum - value;
long otherValue = 0;
if (searchValue != value && this.hashTable.TryGetValue(searchValue, out otherValue))
{
distinctSums.TryAdd(currentSum, new KeyValuePair<long, long>(value, otherValue));
}
}
}
if (currentSum == upperBound)
{
this.Complete.TrySetResult(true);
}
});
twoSum.BeginInvoke(null, null);
}
}
示例14: BeginExecute
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
{
var message = Message.Get(context);
var MarkAsReadDelegate = new Action<EmailMessage>(MarkAsRead);
context.UserState = MarkAsReadDelegate;
return MarkAsReadDelegate.BeginInvoke(message, callback, state);
}
示例15: CheckoutFileIfRequired
private static void CheckoutFileIfRequired(_DTE dte, String fileName)
{
_checkOutAction = (String fn) => dte.SourceControl.CheckOutItem(fn);
var sc = dte.SourceControl;
if (sc != null && sc.IsItemUnderSCC(fileName) && !sc.IsItemCheckedOut(fileName))
_checkOutAction.EndInvoke(_checkOutAction.BeginInvoke(fileName, null, null));
}