Skip to content

Commit

Permalink
Merge pull request #5 from trevoriancox/master
Browse files Browse the repository at this point in the history
Issues 1 & 3 alternate fix: allow explicit setting of SyncContext.
  • Loading branch information
newky2k authored Jan 16, 2017
2 parents b681eba + 923be3a commit bd2263b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/MessageBus/DSoft.Messaging/DSoft.Messaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
<TargetFrameworkProfile>Profile158</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<ReleaseVersion>1.3</ReleaseVersion>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
17 changes: 6 additions & 11 deletions src/MessageBus/DSoft.Messaging/MessageBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class MessageBus

public MessageBus()
{
var aSyncContext = TaskScheduler.FromCurrentSynchronizationContext();

}

#endregion
Expand Down Expand Up @@ -69,10 +67,10 @@ internal MessageBusEventHandlerCollection EventHandlers {
}

/// <summary>
/// Gets or sets the sync context.
/// Gets or sets the sync context for the UI thread.
/// </summary>
/// <value>The sync context.</value>
private TaskScheduler SyncContext
public TaskScheduler SyncContext
{
get;
set;
Expand Down Expand Up @@ -166,11 +164,7 @@ public void DeRegister<T> (Action<object,MessageBusEvent> Action) where T : Mess

private void Execute (Action<object,MessageBusEvent> Action, object Sender, MessageBusEvent Evnt)
{
Task.Factory.StartNew (() => {
Action (Sender, Evnt);
},
CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);

Action(Sender, Evnt);
}

/// <summary>
Expand Down Expand Up @@ -287,9 +281,10 @@ public static void PostEvent (String EventId, object Sender, object[] Data)
/// <param name="Command">Command.</param>
public void RunOnUiThread(Action Command)
{
var cul = Thread.CurrentThread;
if (SyncContext == null)
throw new ArgumentNullException ("SyncContext");

//update the UI
//update the UI
Task.Factory.StartNew(() =>
{
if (Command != null)
Expand Down

0 comments on commit bd2263b

Please sign in to comment.