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


C# SynchronizationContext.Post方法代码示例

本文整理汇总了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);
        }
开发者ID:Prog-Party,项目名称:ProgParty.Skoften,代码行数:56,代码来源:Searcher.cs

示例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);
        }
开发者ID:rknoll,项目名称:presit,代码行数:10,代码来源:PresentationWindow.xaml.cs

示例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;
            }
        }
开发者ID:JonathanTLH,项目名称:PanTiltZoomSystem,代码行数:52,代码来源:ListenerMainWindow.xaml.cs

示例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);
        }
开发者ID:Prog-Party,项目名称:ProgParty.Trending,代码行数:48,代码来源:Searcher.cs

示例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();
        }
开发者ID:RodH257,项目名称:gitextensions,代码行数:30,代码来源:ToolStripGitStatus.cs

示例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);
            }
        }
开发者ID:Slesa,项目名称:Poseidon,代码行数:33,代码来源:InboxViewModel.cs

示例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
        }
开发者ID:sharwell,项目名称:dotnet-threading,代码行数:34,代码来源:AsyncServices.cs

示例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;
 }
开发者ID:antiufo,项目名称:Shaman.Http,代码行数:33,代码来源:CancelableTimout.cs

示例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);
 }
开发者ID:JackFong,项目名称:Dolphin,代码行数:12,代码来源:SocketEventProcessor.cs

示例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();
        }
开发者ID:bleis-tift,项目名称:gitextensions,代码行数:28,代码来源:ToolStripGitStatus.cs

示例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);
		}
开发者ID:tommybiteme,项目名称:X,代码行数:26,代码来源:AsyncServices.cs

示例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());
        }
开发者ID:bartbart,项目名称:gitextensions,代码行数:35,代码来源:ToolStripGitStatus.cs

示例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
        }
开发者ID:endo0407,项目名称:IteratorTasks,代码行数:37,代码来源:AsyncServices.cs

示例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;
        }
开发者ID:azarkevich,项目名称:TortoiseRally,代码行数:35,代码来源:SignDefects.cs

示例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);
 }
开发者ID:AlbertoMonteiro,项目名称:VidaDeProgramadorWP7,代码行数:8,代码来源:ViewModelLocator.cs


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