diff --git a/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadColorBaker.cs b/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadColorBaker.cs index 531ded14e..7395ab6e8 100644 --- a/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadColorBaker.cs +++ b/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadColorBaker.cs @@ -29,10 +29,7 @@ public AutocadColorBaker(ILogger logger) /// /// /// - public async Task ParseColors( - IReadOnlyCollection colorProxies, - IProgress onOperationProgressed - ) + public void ParseColors(IReadOnlyCollection colorProxies, IProgress onOperationProgressed) { var count = 0; foreach (ColorProxy colorProxy in colorProxies) @@ -64,8 +61,6 @@ IProgress onOperationProgressed { _logger.LogError(ex, "Failed parsing color proxy"); } - - await Task.Yield(); } } diff --git a/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadInstanceBaker.cs b/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadInstanceBaker.cs index 35d44abe0..cf3439f7f 100644 --- a/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadInstanceBaker.cs +++ b/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadInstanceBaker.cs @@ -49,7 +49,7 @@ IConverterSettingsStore converterSettings } [SuppressMessage("Maintainability", "CA1506:Avoid excessive class coupling")] - public async Task BakeInstances( + public BakeResult BakeInstances( IReadOnlyCollection<(Collection[] collectionPath, IInstanceComponent obj)> instanceComponents, Dictionary> applicationIdMap, string baseLayerName, @@ -167,7 +167,6 @@ instanceOrDefinition is InstanceProxy instanceProxy } transaction.Commit(); - await Task.Yield(); return new(createdObjectIds, consumedObjectIds, conversionResults); } diff --git a/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadMaterialBaker.cs b/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadMaterialBaker.cs index 4aea349fb..6afc37ebf 100644 --- a/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadMaterialBaker.cs +++ b/Connectors/Autocad/Speckle.Connectors.AutocadShared/HostApp/AutocadMaterialBaker.cs @@ -91,7 +91,7 @@ public void PurgeMaterials(string namePrefix) transaction.Commit(); } - public async Task ParseAndBakeRenderMaterials( + public void ParseAndBakeRenderMaterials( List materialProxies, string baseLayerPrefix, IProgress onOperationProgressed @@ -140,7 +140,6 @@ IProgress onOperationProgressed } transaction.Commit(); - await Task.Yield(); } private (ObjectId, ReceiveConversionResult) BakeMaterial( diff --git a/Connectors/Autocad/Speckle.Connectors.AutocadShared/Operations/Receive/AutocadHostObjectBuilder.cs b/Connectors/Autocad/Speckle.Connectors.AutocadShared/Operations/Receive/AutocadHostObjectBuilder.cs index 6af1fe93c..b2886a27d 100644 --- a/Connectors/Autocad/Speckle.Connectors.AutocadShared/Operations/Receive/AutocadHostObjectBuilder.cs +++ b/Connectors/Autocad/Speckle.Connectors.AutocadShared/Operations/Receive/AutocadHostObjectBuilder.cs @@ -63,13 +63,15 @@ CancellationToken _ // NOTE: This is the only place we apply ISyncToThread across connectors. We need to sync up with main thread here // after GetObject and Deserialization. It is anti-pattern now. Happiness level 3/10 but works. return await _syncToThread - .RunOnThread( - async () => await BuildImpl(rootObject, projectName, modelName, onOperationProgressed).ConfigureAwait(false) - ) + .RunOnThread(async () => + { + await Task.CompletedTask.ConfigureAwait(true); + return BuildSync(rootObject, projectName, modelName, onOperationProgressed); + }) .ConfigureAwait(false); } - private async Task BuildImpl( + private HostObjectBuilderResult BuildSync( Base rootObject, string projectName, string modelName, @@ -108,14 +110,16 @@ IProgress onOperationProgressed // 3 - Bake materials and colors, as they are used later down the line by layers and objects if (unpackedRoot.RenderMaterialProxies != null) { - await _materialBaker - .ParseAndBakeRenderMaterials(unpackedRoot.RenderMaterialProxies, baseLayerPrefix, onOperationProgressed) - .ConfigureAwait(true); + _materialBaker.ParseAndBakeRenderMaterials( + unpackedRoot.RenderMaterialProxies, + baseLayerPrefix, + onOperationProgressed + ); } if (unpackedRoot.ColorProxies != null) { - await _colorBaker.ParseColors(unpackedRoot.ColorProxies, onOperationProgressed).ConfigureAwait(true); + _colorBaker.ParseColors(unpackedRoot.ColorProxies, onOperationProgressed); } // 5 - Convert atomic objects @@ -127,10 +131,6 @@ await _materialBaker { string objectId = atomicObject.applicationId ?? atomicObject.id; onOperationProgressed.Report(new("Converting objects", (double)++count / atomicObjects.Count)); - if (count % 50 == 0) - { - await Task.Delay(10).ConfigureAwait(true); - } try { List convertedObjects = ConvertObject(atomicObject, layerPath, baseLayerPrefix); @@ -155,9 +155,12 @@ await _materialBaker } // 6 - Convert instances - var (createdInstanceIds, consumedObjectIds, instanceConversionResults) = await _instanceBaker - .BakeInstances(instanceComponentsWithPath, applicationIdMap, baseLayerPrefix, onOperationProgressed) - .ConfigureAwait(true); + var (createdInstanceIds, consumedObjectIds, instanceConversionResults) = _instanceBaker.BakeInstances( + instanceComponentsWithPath, + applicationIdMap, + baseLayerPrefix, + onOperationProgressed + ); bakedObjectIds.RemoveAll(id => consumedObjectIds.Contains(id)); bakedObjectIds.AddRange(createdInstanceIds); diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/HostApp/RhinoInstanceBaker.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/HostApp/RhinoInstanceBaker.cs index 8cc716e9f..cafc8ba5c 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/HostApp/RhinoInstanceBaker.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/HostApp/RhinoInstanceBaker.cs @@ -42,7 +42,7 @@ ILogger logger /// Instance definitions and instances that need creating. /// A dict mapping { original application id -> [resulting application ids post conversion] } /// - public async Task BakeInstances( + public BakeResult BakeInstances( IReadOnlyCollection<(Collection[] collectionPath, IInstanceComponent obj)> instanceComponents, Dictionary> applicationIdMap, string baseLayerName, @@ -153,7 +153,6 @@ instanceOrDefinition is InstanceProxy instanceProxy } } - await Task.Yield(); return new(createdObjectIds, consumedObjectIds, conversionResults); } diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Operations/Receive/RhinoHostObjectBuilder.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Operations/Receive/RhinoHostObjectBuilder.cs index 3269efe44..56ca5de86 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Operations/Receive/RhinoHostObjectBuilder.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Operations/Receive/RhinoHostObjectBuilder.cs @@ -55,7 +55,7 @@ ISdkActivityFactory activityFactory } #pragma warning disable CA1506 - public async Task Build( + public Task Build( #pragma warning restore CA1506 Base rootObject, string projectName, @@ -207,9 +207,12 @@ CancellationToken cancellationToken // 6 - Convert instances using (var _ = _activityFactory.Start("Converting instances")) { - var (createdInstanceIds, consumedObjectIds, instanceConversionResults) = await _instanceBaker - .BakeInstances(instanceComponentsWithPath, applicationIdMap, baseLayerName, onOperationProgressed) - .ConfigureAwait(false); + var (createdInstanceIds, consumedObjectIds, instanceConversionResults) = _instanceBaker.BakeInstances( + instanceComponentsWithPath, + applicationIdMap, + baseLayerName, + onOperationProgressed + ); bakedObjectIds.RemoveAll(id => consumedObjectIds.Contains(id)); // remove all objects that have been "consumed" bakedObjectIds.AddRange(createdInstanceIds); // add instance ids @@ -224,7 +227,7 @@ CancellationToken cancellationToken } _converterSettings.Current.Document.Views.Redraw(); - return new HostObjectBuilderResult(bakedObjectIds, conversionResults); + return Task.FromResult(new HostObjectBuilderResult(bakedObjectIds, conversionResults)); } private void PreReceiveDeepClean(string baseLayerName) diff --git a/DUI3/Speckle.Connectors.DUI.WebView/DUI3ControlWebView.xaml.cs b/DUI3/Speckle.Connectors.DUI.WebView/DUI3ControlWebView.xaml.cs index 8ed9cf4ef..0fe9776db 100644 --- a/DUI3/Speckle.Connectors.DUI.WebView/DUI3ControlWebView.xaml.cs +++ b/DUI3/Speckle.Connectors.DUI.WebView/DUI3ControlWebView.xaml.cs @@ -26,7 +26,7 @@ public DUI3ControlWebView(IServiceProvider serviceProvider) public object BrowserElement => Browser; - public Task ExecuteScriptAsyncMethod(string script, CancellationToken cancellationToken) + public Task ExecuteScriptAsyncMethod(string script, CancellationToken cancellationToken) { if (!Browser.IsInitialized) { @@ -34,20 +34,20 @@ public Task ExecuteScriptAsyncMethod(string script, CancellationToken cancellat } bool isAlreadyMainThread = Browser.Dispatcher.CheckAccess(); - if (isAlreadyMainThread) - { - //fire and forget - Browser.ExecuteScriptAsync(script); - } - else - { - Browser.Dispatcher.Invoke( - //fire and forget - () => Browser.ExecuteScriptAsync(script), - DispatcherPriority.Background - ); - } - return Task.CompletedTask; + if (isAlreadyMainThread) + { + //fire and forget + Browser.ExecuteScriptAsync(script); + } + else + { + Browser.Dispatcher.Invoke( + //fire and forget + () => Browser.ExecuteScriptAsync(script), + DispatcherPriority.Background + ); + } + return Task.CompletedTask; } private void OnInitialized(object? sender, CoreWebView2InitializationCompletedEventArgs e) diff --git a/Sdk/Speckle.Connectors.Common/Instances/IInstanceBaker.cs b/Sdk/Speckle.Connectors.Common/Instances/IInstanceBaker.cs index fe6fa4af7..2ed88c836 100644 --- a/Sdk/Speckle.Connectors.Common/Instances/IInstanceBaker.cs +++ b/Sdk/Speckle.Connectors.Common/Instances/IInstanceBaker.cs @@ -14,7 +14,7 @@ public interface IInstanceBaker /// /// /// - Task BakeInstances( + BakeResult BakeInstances( IReadOnlyCollection<(Collection[] collectionPath, IInstanceComponent obj)> instanceComponents, Dictionary applicationIdMap, string baseLayerName,