本文整理汇总了C#中System.Action.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Action.Invoke方法的具体用法?C# Action.Invoke怎么用?C# Action.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Action
的用法示例。
在下文中一共展示了Action.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppUpdateControl
public AppUpdateControl(IEnumerable<IAppVersion> appVersions, Action<IAppVersion> updateAction)
{
this.NewestVersion = appVersions.First();
InitializeComponent();
this.AppIconImage.ImageFailed += (sender, e) => { this.AppIconImage.Source = new BitmapImage(new Uri("/Assets/windows_phone.png", UriKind.RelativeOrAbsolute)); };
this.AppIconImage.Source = new BitmapImage(new Uri(HockeyClient.Current.AsInternal().ApiBaseVersion2 + "apps/" + NewestVersion.PublicIdentifier + ".png"));
this.ReleaseNotesBrowser.Opacity = 0;
this.ReleaseNotesBrowser.Navigated += (sender, e) => { (this.ReleaseNotesBrowser.Resources["fadeIn"] as Storyboard).Begin(); };
this.ReleaseNotesBrowser.NavigateToString(WebBrowserHelper.WrapContent(NewestVersion.Notes));
this.ReleaseNotesBrowser.Navigating += (sender, e) =>
{
e.Cancel = true;
WebBrowserTask browserTask = new WebBrowserTask();
browserTask.Uri = e.Uri;
browserTask.Show();
};
this.InstallAETX.Click += (sender, e) =>
{
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri(HockeyClient.Current.AsInternal().ApiBaseVersion2 + "apps/" + NewestVersion.PublicIdentifier + ".aetx", UriKind.Absolute);
webBrowserTask.Show();
};
this.InstallOverApi.Click += (sender, e) => {
this.Overlay.Visibility = Visibility.Visible;
updateAction.Invoke(NewestVersion);
};
}
示例2: DownloadAsync
public static void DownloadAsync(string url, Action<WebException, WebAlbum> callback)
{
var request = WebRequest.Create(new Uri(url));
_currentRequests.Add(request);
request.BeginGetResponse(ar =>
{
var currrentRequests = (List<WebRequest>)ar.AsyncState;
try
{
using (var response = request.EndGetResponse(ar))
{
var reader = XmlReader.Create(response.GetResponseStream());
callback.Invoke(null, GetAlbumDetails(reader));
}
}
catch (WebException ex)
{
callback.Invoke(ex, null);
}
catch (IOException ex)
{
//callback.Invoke(ex, null);
//TODO: log web response fail (usually after abort)
}
finally
{
currrentRequests.Remove(request);
}
}, _currentRequests);
}
示例3: UploadFiles
public static JsonResult UploadFiles(this Controller controller, Action<UploadedFile> action)
{
if (controller.Request.IsAjaxRequest())
{
try
{
action.Invoke(new UploadedFile(
controller.Server.UrlDecode(controller.Request.Headers["x-file-name"]),
controller.Request.InputStream
));
return new JsonResult { Data = new { success = true } };
}
catch (IOException ex)
{
return new JsonResult { Data = new { success = false, error = ex.Message } };
}
}
else
{
try
{
foreach (var key in controller.Request.Files.AllKeys)
{
var file = controller.Request.Files[key];
action.Invoke(new UploadedFile(file.FileName, file.InputStream));
}
return new JsonResult { Data = new { success = true }, ContentType = "text/html" }; // IE fix
}
catch (IOException ex)
{
return new JsonResult { Data = new { success = false, error = ex.Message }, ContentType = "text/html" }; // IE fix
}
}
}
示例4: Display
public bool Display (string body, string cancelButtonTitle, string acceptButtonTitle = "", Action action = null, bool negativeAction = false)
{
AlertDialog.Builder alert = new AlertDialog.Builder (Forms.Context);
alert.SetTitle ("Alert");
alert.SetMessage (body);
alert.SetNeutralButton (cancelButtonTitle, (senderAlert, args) => {
});
if (acceptButtonTitle != "") {
if (!negativeAction) {
alert.SetPositiveButton (acceptButtonTitle, (senderAlert, args) => {
if (action != null) {
action.Invoke ();
}
});
} else {
alert.SetNegativeButton (acceptButtonTitle, (senderAlert, args) => {
if (action != null) {
action.Invoke ();
}
});
}
}
((Activity)Forms.Context).RunOnUiThread (() => {
alert.Show ();
});
return true;
}
示例5: DisplayMessageUsingAction
public void DisplayMessageUsingAction(Action<string> printMessageAction)
{
ConversionFunction = GetIdAsString;
printMessageAction.Invoke(Name);
printMessageAction.Invoke(Address);
printMessageAction.Invoke(ConversionFunction.Invoke(Id));
}
示例6: WrapTransaction
/// <summary>
/// Wraps code in a BeginTransaction and CommitTransaction
/// </summary>
/// <param name="action">The action.</param>
public void WrapTransaction( Action action )
{
if ( !_transactionInProgress )
{
_transactionInProgress = true;
using ( var dbContextTransaction = this.Database.BeginTransaction() )
{
try
{
action.Invoke();
dbContextTransaction.Commit();
}
catch ( Exception ex )
{
dbContextTransaction.Rollback();
throw ( ex );
}
finally
{
_transactionInProgress = false;
}
}
}
else
{
action.Invoke();
}
}
示例7: DeleteFile
public void DeleteFile(string fileName, Action<bool> completed = null)
{
try {
string imagename = fileName.Replace (".pdf", ".jpeg").Replace (".mp4", ".jpeg");
var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
var directoryname = Path.Combine (documents, "Downloads");
if (Directory.Exists (directoryname)) {
foreach (var file in Directory.GetFiles(directoryname)) {
var item = file.Substring (file.LastIndexOf ("/") + 1, file.Length - 1 - file.LastIndexOf ("/"));
if (item == fileName || item == imagename) {
File.Delete (file);
}
}
}
//File.Delete (fileItem.FilePath.Replace("file://",""));
//File.Delete (fileItem.ThumbPath.Replace("file://",""));
completed.Invoke (true);
} catch {
completed.Invoke (false);
throw;
}
}
示例8: GetRealVideoAddress
public static async Task<string> GetRealVideoAddress(string url, Action<Error> onFail = null)
{
string address = string.Empty;
DataLoader loader = new DataLoader();
await loader.LoadDataAsync(url, response => {
RealVideoAddressData data = JsonSerializer.Deserialize<RealVideoAddressData>(response, true);
if(data.Status.Equals("ok", StringComparison.OrdinalIgnoreCase))
{
address = data.Info;
}
else
{
if(onFail != null)
{
onFail.Invoke(new Error() { Message = data.Info });
}
}
}, error => {
if(onFail != null)
{
onFail.Invoke(error);
}
});
return address;
}
示例9: UsingShared
/// <summary>
/// perform an Action while using a shared lock on main thread.
/// </summary>
/// <param name="safeAction">Action to perform</param>
public static void UsingShared(Action unsafeAction)
{
if (ThreadTracker.IsGameThread)
unsafeAction.Invoke();
else
using (Lock_MainThread.AcquireSharedUsing())
unsafeAction.Invoke();
}
示例10: BuildFromDatasource
void BuildFromDatasource(DataSourcePropertyAttribute dataSourcePropertyAttribute, Action<IEnumerable<string>, bool> itemsCalculated) {
CompositeView compositeView = _propertyEditor.View;
if (compositeView!=null) {
compositeView.ObjectSpace.ObjectChanged += (sender, args) => {
var comboBoxItems = GetComboBoxItems(dataSourcePropertyAttribute);
itemsCalculated.Invoke(comboBoxItems,true);
};
itemsCalculated.Invoke(GetComboBoxItems(dataSourcePropertyAttribute),false);
}
}
示例11: Enqueue
/// <summary>
/// Enqueues another action without considering the cancellation token.
/// </summary>
/// <param name="loop">The loop to extend.</param>
/// <param name="action">The action to enqueue.</param>
/// <param name="priority">The priority of the item.</param>
public static void Enqueue(this IEventLoop loop, Action action, TaskPriority priority = TaskPriority.Normal)
{
if (loop != null)
{
loop.Enqueue(c => action.Invoke(), priority);
}
else
{
action.Invoke();
}
}
示例12: Grid_Loaded
private void Grid_Loaded(object sender, RoutedEventArgs e)
{
try{
ImageSourceConverter isc = new ImageSourceConverter();
string strDir = @"C:\ProgramData\MyIPWebcamTimeLapse\MyIPWebcamTimeLapse\1.0.0.4\192.168.1.13\20130311\";
Action act = new Action(() =>
{
try
{
foreach (string fil in System.IO.Directory.EnumerateFiles(strDir))
{
if (!liss.ContainsKey(fil))
{
ImageSource iss = isc.ConvertFromString(fil) as ImageSource;
liss.Add(fil, iss);
}
}
}
catch (Exception ec)
{
string sdsldkfjsldkjf = ec.Message;
}
});
act.Invoke();
int i = 0;
TimerCallback tc = new TimerCallback((a) => {
act.Invoke();
try
{
SetImageCallback d = new SetImageCallback((ims,_i)=>{
image1.Source = ims;
this.Title =_i+"."+ System.DateTime.Now.ToString("HH:mm:ss");
});
this.Dispatcher.Invoke(d,liss.Select(x => x.Value).ToArray()[i],i);
}
catch (Exception ex)
{
string s = ex.Message;
}
i++;
if(i == liss.Count)
i=1;
});
System.Threading.Timer tim = new Timer(tc,null,0,50);
}
catch (Exception ec)
{
string sdsldkfjsldkjf = ec.Message;
}
}
示例13: ThreadSafeInvoke
public static void ThreadSafeInvoke(DispatcherPriority priority, Action action)
{
if (Application.Current.Dispatcher.CheckAccess())
{
action.Invoke();
}
else
{
Application.Current.Dispatcher.Invoke(priority, new Action(delegate()
{
action.Invoke();
}));
}
}
示例14: DeleteAllMedia
public void DeleteAllMedia(Action<bool> completed = null)
{
try {
var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
var directoryname = Path.Combine (documents, "Downloads");
if (Directory.Exists (directoryname)) {
foreach (var file in Directory.GetFiles(directoryname)) {
File.Delete (file);
}
}
completed.Invoke (true);
} catch (Exception ex) {
completed.Invoke (false);
}
}
示例15: HandleError
internal static bool HandleError(JObject json, Action<int> error)
{
if (json == null)
{
error.Invoke(6); // Illegal Response
return true;
}
if (json["error"] != null)
{
error.Invoke(json["error"].Value<int>(0));
return true;
}
return false;
}