本文整理汇总了C#中System.Threading.SynchronizationContext.Send方法的典型用法代码示例。如果您正苦于以下问题:C# SynchronizationContext.Send方法的具体用法?C# SynchronizationContext.Send怎么用?C# SynchronizationContext.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.SynchronizationContext
的用法示例。
在下文中一共展示了SynchronizationContext.Send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunComparisonProcess
public void RunComparisonProcess(object param)
{
try
{
context = (SynchronizationContext)param;
SetProgressPercentage(0);
Logger.LogInfo("Starting comparison process...");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
EssayComparisonManager.Instance.IsComparisonCompete = false;
EssayComparisonManager.Instance.EssayComparisonPercentage = Compare();
stopwatch.Stop();
var ts = stopwatch.Elapsed;
var elapsedTime = string.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
Logger.LogInfo("Comparison completed. Elapsed time: " + elapsedTime);
SetProgressPercentage(100);
context.Send(OnWorkCompleted, elapsedTime);
}
catch (Exception ex)
{
Logger.LogError("Here is some problem..." + ex);
}
}
示例2: RunReferrengProcess
public void RunReferrengProcess(object param)
{
try
{
context = (SynchronizationContext)param;
UsePercentage = true;
SetProgressPercentage(0);
Logger.LogInfo("Starting referring process...");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
ReferringManager.Instance.IsReferringRunning = true;
Logger.LogInfo("Getting sentence list.");
sentenceList = ReferringManager.Instance.OriginalText.ClearUnnecessarySymbolsInText()
.DivideTextToSentences()
.ClearWhiteSpacesInList()
.RemoveEmptyItemsInList()
.ToLower();
Logger.LogInfo("Getting word list.");
wordList = ReferringManager.Instance.OriginalText.ClearUnnecessarySymbolsInText()
.DivideTextToWords()
.RemoveEmptyItemsInList()
.ToLower();
Logger.LogInfo(string.Format("Text contains {0} sentences and {1} words.", sentenceList.Count, wordList.Count));
Logger.LogInfo("Calculate word weights.");
CalculateWordWeights();
Logger.LogInfo("Calculating sentence weights.");
CalculateSentenceWeights();
Logger.LogInfo("Calculating required sentence count.");
int sentenceCount = goodSentenceList.Count;
int requiredSentenceCount = (int)(sentenceCount * ReferringManager.Instance.ReferringCoefficient);
Logger.LogInfo(string.Format("Required sentences: {0}.", requiredSentenceCount));
ReferringManager.Instance.OriginalTextSentenceCount = sentenceCount;
ReferringManager.Instance.ReferredTextSentenceCount = requiredSentenceCount;
Logger.LogInfo("Taking required sentences with biggest weight.");
var requiredSentences = goodSentenceList.OrderByDescending(c => c.Weight).Take(requiredSentenceCount).ToList();
Logger.LogInfo("Building the essay.");
string essay = EssayBuilder.BuildEssay(requiredSentences, goodSentenceList);
ReferringManager.Instance.ReferredText = essay;
ReferringManager.Instance.IsReferringCompete = true;
ReferringManager.Instance.OrderedWordList = goodWordList.TransformPOSToRussian().OrderByDescending(c => c.Weight).ToList();
//order words and weights by weight only for comfortable view
var showGoodWordList = ReferringManager.Instance.OrderedWordList;
var showGoodSentenceList = goodSentenceList.OrderByDescending(c => c.Weight).ToList();
stopwatch.Stop();
var ts = stopwatch.Elapsed;
var elapsedTime = string.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
Logger.LogInfo("Referring completed. Elapsed time: " + elapsedTime);
SetProgressPercentage(100);
context.Send(OnWorkCompleted, elapsedTime);
}
catch (Exception ex)
{
Logger.LogError("Here is some problem..." + ex);
ReferringManager.Instance.IsReferringRunning = false;
}
}
示例3: GetRender
public RenderBuffer GetRender(string url, SynchronizationContext synchronizationContext)
{
WebView webView = null;
synchronizationContext.Send((object state) => webView = WebCore.CreateWebView(1024, 768), null);
synchronizationContext.Send(((object state) => webView.LoadURL(url)), null);
while (webView.IsLoadingPage)
SleepAndUpdateCore(synchronizationContext);
webView.RequestScrollData();
webView.ScrollDataReceived += OnScrollDataReceived;
while (!_finishedScrollDataReceived)
SleepAndUpdateCore(synchronizationContext);
var width = _scrollData.ContentWidth > MaxWidth ? MaxWidth : _scrollData.ContentWidth;
var height = _scrollData.ContentHeight > MaxHeight ? MaxHeight : _scrollData.ContentHeight;
webView.Resize(width, height);
while (webView.IsResizing)
SleepAndUpdateCore(synchronizationContext);
return webView.Render();
}
示例4: KinectReplay
public KinectReplay(string fileName)
{
Started = false;
stream = File.OpenRead(fileName);
reader = new BinaryReader(stream);
synchronizationContext = SynchronizationContext.Current;
Options = (KinectRecordOptions)reader.ReadInt32();
//var paramsArrayLength = reader.ReadInt32();
//var colorToDepthRelationalParameters = reader.ReadBytes(paramsArrayLength);
//CoordinateMapper = new CoordinateMapper(colorToDepthRelationalParameters);
if ((Options & KinectRecordOptions.Frames) != 0)
{
framesReplay = new ReplayAllFramesSystem();
framesReplay.AddFrames(reader);
framesReplay.ReplayFinished += () => synchronizationContext.Send(state => ReplayFinished.Raise(),null);
}
if ((Options & KinectRecordOptions.Audio) != 0)
{
var audioFilePath = Path.ChangeExtension(fileName, ".wav");
if (File.Exists(audioFilePath))
AudioFilePath = audioFilePath;
}
}
示例5: Main
/// <summary>
/// Entry point of the application.
/// </summary>
/// <param name="args">An array of command line arguments.</param>
public static void Main(string[] args)
{
try {
var context = new SynchronizationContext();
context.Send((x) => TaskMain().Wait(), null);
} catch (AggregateException E) {
throw E.InnerException;
}
}
示例6: CloverExamplePOSForm
public CloverExamplePOSForm()
{
InitializeComponent();
uiThread = WindowsFormsSynchronizationContext.Current;
uiThread.Send(delegate (object state)
{
new StartupForm(this).Show();
}, null);
}
示例7: SetTrayVisibleIndeterminent
internal static void SetTrayVisibleIndeterminent(this Page containerPage, String message, SynchronizationContext syncContext)
{
syncContext.Send(callback =>
{
SystemTray.SetIsVisible(containerPage, true);
SystemTray.SetOpacity(containerPage, 0.5);
var indicator = new ProgressIndicator {Text = message, IsVisible = true, IsIndeterminate = true};
SystemTray.SetProgressIndicator(containerPage, indicator);
}, null);
}
示例8: DoFlash
private static void DoFlash(IVectorGraphic graphic, SynchronizationContext context)
{
context.Send(delegate
{
if (graphic.ImageViewer != null && graphic.ImageViewer.DesktopWindow != null)
{
graphic.Color = _invalidColor;
graphic.Draw();
}
}, null);
Thread.Sleep(_flashDelay);
context.Send(delegate
{
if (graphic.ImageViewer != null && graphic.ImageViewer.DesktopWindow != null)
{
graphic.Color = _normalColor;
graphic.Draw();
}
}, null);
}
示例9: DisposeWithViewModelTestControl
public DisposeWithViewModelTestControl()
{
InitializeComponent();
syncContext = SynchronizationContext.Current;
placeholder.Disposed += delegate
{
syncContext.Send(state => UpdateText(), null);
};
UpdateText();
}
示例10: FlowController
internal static async Task FlowController(this FrameworkElement fx, IEnumerable<Movie> movies, SynchronizationContext syncContext)
{
while (true)
{
await Task.Delay(TimeSpan.FromSeconds(Rand(7, 12))).ContinueWith(task => syncContext.Send(callback =>
{
var storyBd = fx.FindName("Update") as Storyboard;
if (storyBd != null)
storyBd.Begin();
fx.DataContext = movies.Shuffle();
}, null));
}
}
示例11: AddNotificationsSource
public static void AddNotificationsSource(WordList list)
{
// REDO: for multiple sources of notifications
wordList = list;
if (notificationsTimer == null)
{
notificationsTimer = new System.Timers.Timer();
notificationsTimer.Interval = 6000; //1000*60;
notificationsTimer.AutoReset = false;
notificationsTimer.Elapsed += notificationsTimer_Elapsed;
notificationsTimer.Start();
uiContext = SynchronizationContext.Current;
uiContext.Send(ShowNotification, "test");
}
}
示例12: P2PService
/// <summary>
/// Создает экземпляр сервиса для функционирования UDP hole punching. Без логирования.
/// </summary>
public P2PService(int port, bool usingIPv6)
{
disposed = false;
requests = new List<RequestPair>();
clientsEndPoints = new Dictionary<string, ClientDescription>();
connectingClients = new HashSet<string>();
NetPeerConfiguration config = new NetPeerConfiguration(AsyncPeer.NetConfigString);
config.MaximumConnections = 100;
config.Port = port;
if (usingIPv6)
config.LocalAddress = IPAddress.IPv6Any;
syncContext = new EngineSyncContext();
server = new NetServer(config);
syncContext.Send(s => ((NetServer)s).RegisterReceivedCallback(ReceivedCallback), server);
server.Start();
}
示例13: Start
public void Start()
{
context = SynchronizationContext.Current;
CancellationToken token = cancellationTokenSource.Token;
Task.Factory.StartNew(() =>
{
foreach (ReplaySkeletonFrame frame in frames)
{
Thread.Sleep(TimeSpan.FromMilliseconds(frame.TimeStamp));
if (token.IsCancellationRequested)
return;
ReplaySkeletonFrame closure = frame;
context.Send(state =>
{
if (SkeletonFrameReady != null)
SkeletonFrameReady(this, new ReplaySkeletonFrameReadyEventArgs {SkeletonFrame = closure});
}, null);
}
}, token);
}
示例14: SetTrayCollapsed
internal static Task SetTrayCollapsed(this Page containerPage, SynchronizationContext syncContext)
{
Thread.Sleep(2000);
syncContext.Send(callback => SystemTray.SetIsVisible(containerPage, false), null);
return null;
}
示例15: __InitPreviewForUris
static void __InitPreviewForUris(
List<PathAndDrawable> list,
CancellationToken ct,
SynchronizationContext sync,
Android.Content.Res.Resources res,
Action callback)
{
for (int i = 0; i < list.Count && !ct.IsCancellationRequested; i++)
{
var uad = list[i];
if (uad.path.IsImage())
{
try
{
uad.drawable = GetResized(Drawable.CreateFromPath(uad.path), res);
}
catch (Exception ex)
{
ex.Handle(true);
}
}
list[i] = uad;
if (!ct.IsCancellationRequested && callback != null && sync != null)
sync.Send(new SendOrPostCallback(state => callback()), null);
}
}