Questions tagged [synchronizationcontext]

A .NET target to dispatch some work to. In winforms and WPF this is usually to the main UI thread.

A .NET target to dispatch some work to. In winforms and WPF this is usually to the main UI thread.

References

173 questions
0
votes
1 answer

How do I implement thread affinity in C#?

I have a third-party API which requires thread affinity. I am using WCF in my service application to handle requests from a client which are then delegated to this API. Since WCF uses a thread pool to handle requests, I attempted to work around this…
markf78
  • 597
  • 2
  • 7
  • 25
0
votes
2 answers

Await in Unit tests and EntityFramework stored in CallContext.SetData

I have MVC web app that uses EntityFramework context and it stores it in HttpContext.Current.Items. When HttpContext.Current isn't available then it uses CallContext.SetData to store data in current thread storage. HttpContext is used for web app…
0
votes
1 answer

How to "restore" SynchronizationContext when using custom startup?

My app works fine, but now I wanted to have custom startup, so I could catch any errors, add my logging from the start, etc. So I used approach as shown in this answer What code controls the startup of a WPF application? [STAThread] public static…
astrowalker
  • 3,123
  • 3
  • 21
  • 40
0
votes
0 answers

how to invoke workflow on same thread as calling thread

I'm using WF to run activities and I would like to invoke the activity synchronously on the same thread as the calling thread. How would I do that using WorkflowInvoker.Invoke? The following is my code snippet: public int…
0
votes
1 answer

Discard other than the last in the control's SynchronizationContext post queue

Suppose a UI update takes quite a long time. As an example, this dummy label takes 1 second to change the text. public class MyLabel : Label { public override string Text { get { return base.Text; } set { …
Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
0
votes
0 answers

How to set culture in Web API 2 compatible with async/await?

I have a REST service that generates string messages with currencies and dates, so I need the right culture to be set up. Messages are produced in different steps that runs between asynchronous operations. Web API will set the culture coming in the…
0
votes
1 answer

NUnit 3, await, dead-lock and UI

Problem Statement We have tests that, at some point, cause a SynchronizationContext to be set on the current nunit thread. Mixing this with await causes a dead-lock to the best of my knowledge. The issue is that we mix business logic with UI…
Sven
  • 175
  • 1
  • 8
0
votes
0 answers

Why do we need a SynchronizationContext in the EventAggregator for WPF

I have read quiet a few implementations of the EventAggregator (Messenger) to communicate between different ViewModels in WPF but I am having difficulties why we necessarily need to use a SynchronizationContext. I understand that the…
0
votes
0 answers

TaskScheduler.FromCurrentSynchronizationContext() crashing my application

I have a console application and my first line is in the Main method is: TaskScheduler.FromCurrentSynchronizationContext(); but here my application crashes with the System.InvalidOperationException : Additional information: The current…
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
0
votes
1 answer

Can't set synchronization context when using appdomains

I have a custom framework where a host application runs an event loop and loads a guest application into a separate app-domain. The guest application has means to take advantage of the event loop via a provided API. I want to make the guest…
0
votes
1 answer

Pass SynchronizationContext to ViewModel when it's in a different projects

I have WPF application implemented with classic MVVM pattern, however View, Model and ViewModel are three different projects in my solution. I have well-known implementation of AsyncObservebleCollection in my ViewModel public class MyVM :…
inside
  • 3,047
  • 10
  • 49
  • 75
0
votes
2 answers

C# Application.DoEvents cannot work in my application

As my English is not well, I explain my question simple and paste a code snippet here to describe the problem. The problem is a multiple threading issue in our winForm application. I simple the logic as following code sample. In the test code, there…
0
votes
2 answers

Behavior of setting ConfigureAwait and SynchronisationContext

In his answer Stephen explained that when ConfigureAwait(false) is called the rest of the method will be executed on a thread pool thread unless the Task you're awaiting is already complete. What is clear: If I use ConfigureAwait(false) everything…
Batz
  • 13
  • 2
0
votes
2 answers

Is it possible to pass a Task (with return value) to an existing (i.e already running) Thread

In wpf I have two windows in separate threads. From Window A' in Thread A I would like to start a Task in Tread B of Window B' and await the return value in Thread A. It suppose it is possible but how? Do you know an example perhaps?
Gerard
  • 13,023
  • 14
  • 72
  • 125
0
votes
1 answer

How can I suppress ExecutionContext capturing the current SynchronizationContext?

My question was raised by one of the examples from this article: private void button1_Click(object sender, EventArgs e) { button1.Text = await Task.Run(async delegate { string data = await DownloadAsync(); return…
Redwood
  • 66,744
  • 41
  • 126
  • 187
1 2 3
11
12