diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs index 6b6b227517c..1f50bdff34f 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs @@ -850,7 +850,7 @@ public static void SetDisplayRotationCapability(Rotation rotation, MediaControlC command.SetRequestInformation(clientId); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); string reqeustId = null; Bundle bundle = null; @@ -909,7 +909,7 @@ public static async Task RequestAsync(Command command, string clientId) command.SetRequestInformation(clientId); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); string reqeustId = null; Bundle bundle = null; diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs index 6aaf55d5e23..9d52796b4f3 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs @@ -853,7 +853,7 @@ public IEnumerable GetDisplayRotationCapability() command.SetRequestInformation(ServerAppId); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); string reqeustId = null; Bundle bundle = null; @@ -918,7 +918,7 @@ public async Task RequestAsync(Command command) command.SetRequestInformation(ServerAppId); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); string reqeustId = null; Bundle bundle = null; diff --git a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroring.cs b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroring.cs index 80ea9ddd222..5f0091566ba 100644 --- a/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroring.cs +++ b/src/Tizen.Multimedia.Remoting/ScreenMirroring/ScreenMirroring.cs @@ -262,23 +262,15 @@ private void PrepareCore(Display display, ScreenMirroringResolutions resolutions private Task RunAsync(Func func, string failMessage) { - var tcs = new TaskCompletionSource(); - - Task.Run(() => + return Task.Run(() => { var ret = func(Handle); - if (ret == ScreenMirroringErrorCode.None) + if (ret != ScreenMirroringErrorCode.None) { - tcs.SetResult(true); - } - else - { - tcs.SetException(ret.AsException(failMessage)); + throw ret.AsException(failMessage); } }); - - return tcs.Task; } /// diff --git a/src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs b/src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs index a6d3ce2857e..c918c827aa6 100755 --- a/src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs +++ b/src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs @@ -168,7 +168,7 @@ public async Task StartAsync() ValidateWebRTCState(WebRTCState.Idle); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var error = WebRTCError.ConnectionFailed; EventHandler stateChangedEventHandler = (s, e) => @@ -193,7 +193,6 @@ public async Task StartAsync() NativeWebRTC.Start(Handle).ThrowIfFailed("Failed to start the WebRTC"); var result = await tcs.Task.ConfigureAwait(false); - await Task.Yield(); if (!result) { @@ -244,7 +243,7 @@ public async Task CreateOfferAsync() ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing); - var tcsSdpCreated = new TaskCompletionSource(); + var tcsSdpCreated = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); NativeWebRTC.SdpCreatedCallback cb = (handle, sdp, _) => { @@ -258,7 +257,6 @@ public async Task CreateOfferAsync() ThrowIfFailed("Failed to create offer asynchronously"); offer = await tcsSdpCreated.Task.ConfigureAwait(false); - await Task.Yield(); } Log.Info(WebRTCLog.Tag, "Leave"); @@ -283,7 +281,7 @@ public async Task CreateAnswerAsync() ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing); - var tcsSdpCreated = new TaskCompletionSource(); + var tcsSdpCreated = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); NativeWebRTC.SdpCreatedCallback cb = (handle, sdp, _) => { @@ -297,7 +295,6 @@ public async Task CreateAnswerAsync() ThrowIfFailed("Failed to create answer asynchronously"); answer = await tcsSdpCreated.Task.ConfigureAwait(false); - await Task.Yield(); } Log.Info(WebRTCLog.Tag, "Leave");