本文整理汇总了C#中System.Threading.SynchronizationContext.Post方法的典型用法代码示例。如果您正苦于以下问题:C# SynchronizationContext.Post方法的具体用法?C# SynchronizationContext.Post怎么用?C# SynchronizationContext.Post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.SynchronizationContext
的用法示例。
在下文中一共展示了SynchronizationContext.Post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteGaleryScrape
public static void ExecuteGaleryScrape(MainPage mainpage, SynchronizationContext context, Api.Parameter.OverviewParameter parameters = null)
{
if (parameters == null)
parameters = new Api.Parameter.OverviewParameter();
context.Post((_) =>
{
mainpage.SkoftenDataContext.GalleryItemsLoading = true;
}, null);
parameters.Type = mainpage.SkoftenDataContext.CurrentGalleryType;
if (parameters.StartOver)
{
mainpage.SkoftenDataContext.GalleryPaging = 0;
mainpage.SkoftenDataContext.GalleryItemIndex = 0;
mainpage.SkoftenDataContext.SelectedGallery = 0;
}
parameters.Paging = mainpage.SkoftenDataContext.GalleryPaging;
mainpage.SkoftenDataContext.GalleryPaging += 12;
OverviewExecute oe = new OverviewExecute();
oe.Parameters = parameters;
oe.Execute();
var result = oe.Result;
context.Post((_) =>
{
if(parameters.StartOver)
{
mainpage.SkoftenDataContext.Gallery.Clear();
}
foreach (var item in result)
{
if(parameters.Type == Api.Parameter.OverviewType.EroDump)
{
if (!item.Url.Contains("babes.skoften.net"))
{
mainpage.SkoftenDataContext.GalleryItemIndex++;
continue;
}
}
item.Index = mainpage.SkoftenDataContext.GalleryItemIndex;
mainpage.SkoftenDataContext.Gallery.Add(item);
mainpage.SkoftenDataContext.GalleryItemIndex++;
}
mainpage.SkoftenDataContext.GalleryItemsLoading = false;
}, null);
}
示例2: PresentationWindow
public PresentationWindow(IMainWindowPresenter dataContext)
{
InitializeComponent();
context = SynchronizationContext.Current;
// register callbacks for slide control
dataContext.NextSlide += (o, args) => context.Post(state => NextSlide(), null);
dataContext.PreviousSlide += (o, pres) => context.Post(state => PreviousSlide(), null);
dataContext.SwitchPause += (o, pres) => context.Post(state => SwitchPause(), null);
}
示例3: MainWindow_Loaded
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
var deviceName = ConfigurationManager.AppSettings["DeviceName"];
device = PTZDevice.GetDevice(deviceName, PTZType.Relative);
url = ConfigurationManager.AppSettings["relayServerUrl"];
remoteGroup = Environment.MachineName; //They have to hardcode the group, but for us it's our machine name
connection = new HubConnection(url);
proxy = connection.CreateHubProxy("RelayHub");
connection.TraceLevel = TraceLevels.StateChanges | TraceLevels.Events;
connection.TraceWriter = new PTZRemoteTraceWriter(Log);
//Can't do this here because DirectShow has to be on the UI thread!
// This would cause an obscure COM casting error with no clue what's up. So, um, ya.
//proxy.On<int, int>("Move",(x,y) => device.Move(x, y));
//proxy.On<int>("Zoom", (z) => device.Zoom(z));
magic = SynchronizationContext.Current;
proxy.On<int, int>("Move", (x, y) =>
{
//Toss this over the fence from this background thread to the UI thread
magic.Post((_) => {
Log(String.Format("Move({0},{1})", x,y));
device.Move(x, y);
}, null);
});
proxy.On<int>("Zoom", (z) =>
{
magic.Post((_) =>
{
Log(String.Format("Zoom({0})", z));
device.Zoom(z);
}, null);
});
try
{
await connection.Start();
Log("After connection.Start()");
await proxy.Invoke("JoinRelay", remoteGroup);
Log("After JoinRelay");
}
catch (Exception pants)
{
Log(pants.GetError().ToString());
throw;
}
}
示例4: ExecuteGaleryScrape
public static void ExecuteGaleryScrape(MainPage mainpage, SynchronizationContext context, Api.Parameter.OverviewParameter parameters = null)
{
if (parameters == null)
parameters = new Api.Parameter.OverviewParameter();
context.Post((_) =>
{
mainpage.PageDataContext.GalleryItemsLoading = true;
if (parameters.StartOver)
mainpage.PageDataContext.Gallery.Clear();
}, null);
parameters.Category = mainpage.PageDataContext.CurrentArticleGallery;
if (parameters.StartOver)
{
mainpage.PageDataContext.GalleryPaging = -1;
mainpage.PageDataContext.GalleryItemIndex = 0;
mainpage.PageDataContext.SelectedGallery = 0;
}
mainpage.PageDataContext.GalleryPaging += 1;
parameters.Paging = mainpage.PageDataContext.GalleryPaging;
OverviewExecute oe = new OverviewExecute();
oe.Parameters = parameters;
oe.Execute();
var result = oe.Result;
context.Post((_) =>
{
if (parameters.StartOver)
{
mainpage.PageDataContext.Gallery.Clear();
}
foreach (var item in result)
{
item.Index = mainpage.PageDataContext.GalleryItemIndex;
mainpage.PageDataContext.Gallery.Add(item);
mainpage.PageDataContext.GalleryItemIndex++;
}
mainpage.PageDataContext.GalleryItemsLoading = false;
}, null);
}
示例5: ToolStripGitStatus
public ToolStripGitStatus()
{
syncContext = SynchronizationContext.Current;
gitGetUnstagedCommand.Exited += (o, ea) => syncContext.Post(_ => onData(), null);
InitializeComponent();
Settings.WorkingDirChanged += Settings_WorkingDirChanged;
GitUICommands.Instance.PreCheckoutBranch += GitUICommands_PreCheckout;
GitUICommands.Instance.PreCheckoutRevision += GitUICommands_PreCheckout;
GitUICommands.Instance.PostCheckoutBranch += GitUICommands_PostCheckout;
GitUICommands.Instance.PostCheckoutRevision += GitUICommands_PostCheckout;
// Setup a file watcher to detect changes to our files, or the .git repo files. When they
// change, we'll update our status.
watcher.Changed += watcher_Changed;
watcher.Created += watcher_Changed;
watcher.Deleted += watcher_Changed;
watcher.Error += watcher_Error;
watcher.IncludeSubdirectories = true;
try
{
watcher.Path = Settings.WorkingDir;
watcher.EnableRaisingEvents = true;
}
catch { }
update();
}
示例6: InboxViewModel
public InboxViewModel(IEmailService emailService, IRegionManager regionManager)
{
synchronizationContext = SynchronizationContext.Current ?? new SynchronizationContext();
_composeMessageCommand = new DelegateCommand<object>(ComposeMessage);
_replyMessageCommand = new DelegateCommand<object>(ReplyMessage, CanReplyMessage);
_openMessageCommand = new DelegateCommand<EmailDocument>(OpenMessage);
messagesCollection = new ObservableCollection<EmailDocument>();
Messages = new CollectionView(this.messagesCollection);
Messages.CurrentChanged += (s, e) =>
_replyMessageCommand.RaiseCanExecuteChanged();
_emailService = emailService;
_regionManager = regionManager;
if (_emailService != null)
{
_emailService.BeginGetEmailDocuments(
r =>
{
var messages = _emailService.EndGetEmailDocuments(r);
synchronizationContext.Post(
s =>
{
foreach (var message in messages)
{
messagesCollection.Add(message);
}
}, null);
}, null);
}
}
示例7: ThrowAsync
/// <summary>Throws the exception on the thread pool.</summary>
/// <param name="exception">The exception to propagate.</param>
/// <param name="targetContext">
/// The target context on which to propagate the exception; otherwise, <see langword="null"/> to use the thread
/// pool.
/// </param>
internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
{
// If the user supplied a SynchronizationContext...
if (targetContext != null)
{
try
{
// Post the throwing of the exception to that context, and return.
targetContext.Post(state => { throw PrepareExceptionForRethrow((Exception)state); }, exception);
return;
}
catch (Exception postException)
{
// If something goes horribly wrong in the Post, we'll propagate both exceptions on the thread pool
exception = new AggregateException(exception, postException);
}
}
#if NET45PLUS
Task.Run(() =>
{
throw PrepareExceptionForRethrow(exception);
});
#else
// Propagate the exception(s) on the ThreadPool
ThreadPool.QueueUserWorkItem(state => { throw PrepareExceptionForRethrow((Exception)state); }, exception);
#endif
}
示例8: ScheduleInternal
private static CancellableTimout ScheduleInternal(Action action, int delay, SynchronizationContext syncCtx)
{
var c = new CancellableTimout();
c.action = action;
c.syncCtx = syncCtx;
var t = new Timer(state =>
{
var cc = (CancellableTimout)state;
var a = cc.action;
if (a != null)
{
if (cc.syncCtx != null)
{
syncCtx.Post(new SendOrPostCallback(z =>
{
using (cc)
{
if (cc.action != null) a();
}
}), null);
return;
}
else
{
a();
}
}
cc.Dispose();
}, c, delay, Timeout.Infinite);
c.timer = t;
c.delay = delay;
return c;
}
示例9: InvokeConnectionClosed
/// <summary>
/// 处理连接关闭事件
/// </summary>
/// <param name="e"></param>
/// <param name="context"></param>
protected virtual void InvokeConnectionClosed(SocketModuleEventArgs e, SynchronizationContext context)
{
if (null != context)
context.Post(HandlerConnectionClosed, e);
else
HandlerConnectionClosed(e);
}
示例10: ToolStripGitStatus
public ToolStripGitStatus()
{
syncContext = SynchronizationContext.Current;
gitGetUnstagedCommand.Exited += new EventHandler(delegate(object o, EventArgs ea)
{
syncContext.Post(_ => onData(), null);
});
InitializeComponent();
Settings.WorkingDirChanged += new Settings.WorkingDirChangedHandler(Settings_WorkingDirChanged);
// Setup a file watcher to detect changes to our files, or the .git repo files. When they
// change, we'll update our status.
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.Created += new FileSystemEventHandler(watcher_Changed);
watcher.Deleted += new FileSystemEventHandler(watcher_Changed);
watcher.Error += new ErrorEventHandler(watcher_Error);
watcher.IncludeSubdirectories = true;
try
{
watcher.Path = Settings.WorkingDir;
watcher.EnableRaisingEvents = true;
}
catch { }
update();
}
示例11: ThrowAsync
internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
{
if (targetContext != null)
{
try
{
targetContext.Post(delegate(object state)
{
throw AsyncServices.PrepareExceptionForRethrow((Exception)state);
}, exception);
return;
}
catch (Exception ex)
{
exception = new AggregateException(new Exception[]
{
exception,
ex
});
}
}
ThreadPool.QueueUserWorkItem(delegate(object state)
{
throw AsyncServices.PrepareExceptionForRethrow((Exception)state);
}, exception);
}
示例12: ToolStripGitStatus
public ToolStripGitStatus()
{
syncContext = SynchronizationContext.Current;
gitGetUnstagedCommand.Exited += (o, ea) => syncContext.Post(_ => onData(), null);
InitializeComponent();
CommitTranslatedString = "Commit";
Settings.WorkingDirChanged += (_, newDir, newGitDir) => TryStartWatchingChanges(newDir, newGitDir);
GitUICommands.Instance.PreCheckoutBranch += GitUICommands_PreCheckout;
GitUICommands.Instance.PreCheckoutRevision += GitUICommands_PreCheckout;
GitUICommands.Instance.PostCheckoutBranch += GitUICommands_PostCheckout;
GitUICommands.Instance.PostCheckoutRevision += GitUICommands_PostCheckout;
// Setup a file watcher to detect changes to our files. When they
// change, we'll update our status.
watcher.Changed += watcher_Changed;
watcher.Created += watcher_Changed;
watcher.Deleted += watcher_Changed;
watcher.Error += watcher_Error;
watcher.IncludeSubdirectories = true;
watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
// Setup a file watcher to detect changes to the .git repo files. When they
// change, we'll update our status.
gitDirWatcher.Changed += gitWatcher_Changed;
gitDirWatcher.Created += gitWatcher_Changed;
gitDirWatcher.Deleted += gitWatcher_Changed;
gitDirWatcher.Error += watcher_Error;
gitDirWatcher.IncludeSubdirectories = true;
gitDirWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
TryStartWatchingChanges(Settings.WorkingDir, Settings.Module.GetGitDirectory());
}
示例13: ThrowAsync
/// <summary>Throws the exception on the thread pool.</summary>
/// <param name="exception">The exception to propagate.</param>
/// <param name="targetContext">
/// The target context on which to propagate the exception; otherwise, <see langword="null"/> to use the thread
/// pool.
/// </param>
internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
{
if (targetContext != null)
{
try
{
targetContext.Post(
state =>
{
throw PrepareExceptionForRethrow((Exception)state);
}, exception);
return;
}
catch (Exception ex)
{
exception = new AggregateException(exception, ex);
}
}
#if NET45PLUS
Task.Run(() =>
{
throw PrepareExceptionForRethrow(exception);
});
#else
ThreadPool.QueueUserWorkItem(state =>
{
throw PrepareExceptionForRethrow((Exception)state);
}, exception);
#endif
}
示例14: DoSign
int DoSign(IEnumerable<Artifact> artifacts, SynchronizationContext sc)
{
var restApi = new RallyRestApi(Settings.Default.RallyUser, Settings.Default.RallyPassword
//, proxy: new WebProxy("localhost:8888", false)
);
foreach (var tagArt in artifacts)
{
var toCreate = new DynamicJsonObject();
toCreate["Text"] = "%FIX_CODE_REVIEW_PASSED%";
toCreate["Artifact"] = tagArt.Reference;
var createResult = restApi.Create("ConversationPost", toCreate);
// update status
sc.Post(_ => {
var lvi = listViewArtifacts.Items.Cast<ListViewItem>().FirstOrDefault(l => l.Tag == tagArt);
if (!createResult.Success)
{
lvi.BackColor = Color.Tomato;
if (createResult.Errors.Count > 0)
lvi.SubItems[1].Text = createResult.Errors[0];
else
lvi.SubItems[1].Text = "Unexpected error";
}
else
{
lvi.BackColor = Color.LightGreen;
lvi.SubItems[3].Text = "✔";
}
}, null);
}
return 0;
}
示例15: CarregaTirinhas
public async void CarregaTirinhas()
{
synchronizationContext = SynchronizationContext.Current;
var p = new PostsService();
var tirinhas = await p.GetPosts(0, tirinha => true);
foreach (var tirinha in tirinhas)
synchronizationContext.Post(state => { Tirinhas.Add(tirinha); }, null);
}