当前位置: 首页>>代码示例>>C#>>正文


C# Task.AsAsyncOperation方法代码示例

本文整理汇总了C#中System.Threading.Tasks.Task.AsAsyncOperation方法的典型用法代码示例。如果您正苦于以下问题:C# Task.AsAsyncOperation方法的具体用法?C# Task.AsAsyncOperation怎么用?C# Task.AsAsyncOperation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Tasks.Task的用法示例。


在下文中一共展示了Task.AsAsyncOperation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDoorStateAsync

 public IAsyncOperation<GarageDoorGetDoorStateResult> GetDoorStateAsync(AllJoynMessageInfo info)
 {
     Task<GarageDoorGetDoorStateResult> task = new Task<GarageDoorGetDoorStateResult>(() =>
     {
         var newState = new GarageDoorDoorState();
         var status = _driver.GetCurrentStatus();
         newState.Value1 = Convert.ToByte(status);
         switch(status)
         {
             case DoorStatus.Closed:
                 newState.Value2 = "Closed";
                 break;
             case DoorStatus.Opened:
                 newState.Value2 = "Opened";
                 break;
             case DoorStatus.Closing:
                 newState.Value2 = "Closing";
                 break;
             case DoorStatus.Opening:
                 newState.Value2 = "Opening";
                 break;
             default:
                 newState.Value2 = "Unknown";
                 break;
         }
         return GarageDoorGetDoorStateResult.CreateSuccessResult(newState);
     });
     task.Start();
     return task.AsAsyncOperation();
 }
开发者ID:mlinnen,项目名称:HacksterIOWin10IoT,代码行数:30,代码来源:GarageDoorService.cs

示例2: GetLocationAsync

 public IAsyncOperation<GarageDoorGetLocationResult> GetLocationAsync(AllJoynMessageInfo info)
 {
     Task<GarageDoorGetLocationResult> task = new Task<GarageDoorGetLocationResult>(() =>
     {
         return GarageDoorGetLocationResult.CreateSuccessResult(_location);
     });
     task.Start();
     return task.AsAsyncOperation();
 }
开发者ID:mlinnen,项目名称:HacksterIOWin10IoT,代码行数:9,代码来源:GarageDoorService.cs

示例3: GetStateAsync

        public IAsyncOperation<relaynodeGetStateResult> GetStateAsync(AllJoynMessageInfo info, int interfaceMemberRelayId)
        {
            Task<relaynodeGetStateResult> task = new Task<relaynodeGetStateResult>(() =>
            {
                return relaynodeGetStateResult.CreateSuccessResult((byte)(_hm.GetRelayState(interfaceMemberRelayId ) ? 1 : 0));
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:martincalsyn,项目名称:CortanaAllJoynDemo,代码行数:10,代码来源:relayService.cs

示例4: GetDarknessAsync

        // Implement this function to handle requests for the value of the Darkness property.
        //
        // Currently, info will always be null, because no information is available about the requestor.
        public IAsyncOperation<toasterGetDarknessResult> GetDarknessAsync(AllJoynMessageInfo info)
        {
            Task<toasterGetDarknessResult> task = new Task<toasterGetDarknessResult>(() =>
            {
                return toasterGetDarknessResult.CreateSuccessResult(darkness);
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:snowzk,项目名称:AllJoynToasterDemo,代码行数:13,代码来源:toasterService.cs

示例5: GetIsUpperCaseEnabledAsync

        // Method to handle requests for the value of the IsUpperCaseEnabled property.
        public IAsyncOperation<SecureInterfaceGetIsUpperCaseEnabledResult> GetIsUpperCaseEnabledAsync(AllJoynMessageInfo info)
        {
            Task<SecureInterfaceGetIsUpperCaseEnabledResult> task = new Task<SecureInterfaceGetIsUpperCaseEnabledResult>(() =>
            {
                return SecureInterfaceGetIsUpperCaseEnabledResult.CreateSuccessResult(AppData.IsUpperCaseEnabled);
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:t-angma,项目名称:Windows-universal-samples,代码行数:11,代码来源:SecureInterfaceService.cs

示例6: SendAsync

        public IAsyncOperation<CharacterLCDSendResult> SendAsync(AllJoynMessageInfo info, string interface_message)
        {
            Task<CharacterLCDSendResult> task = new Task<CharacterLCDSendResult>(() =>
            {
                lcd.WriteLCD(interface_message);
                return CharacterLCDSendResult.CreateSuccessResult();
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:Robotonics,项目名称:CharacterLCD,代码行数:11,代码来源:CharacterLCDService.cs

示例7: StartToastingAsync

        // Implement this function to handle calls to the startToasting method.
        public IAsyncOperation<toasterStartToastingResult> StartToastingAsync(AllJoynMessageInfo info)
        {
            Task<toasterStartToastingResult> task = new Task<toasterStartToastingResult>(() =>
            {
                Task.Delay(TimeSpan.FromSeconds(darkness)).ContinueWith(_ => _toasterSignals.ToastDone(AllJoynStatus.Ok));
                return toasterStartToastingResult.CreateSuccessResult();
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:snowzk,项目名称:AllJoynToasterDemo,代码行数:12,代码来源:toasterService.cs

示例8: SetDarknessAsync

        // Implement this function to handle requests to set the Darkness property.
        //
        // Currently, info will always be null, because no information is available about the requestor.
        public IAsyncOperation<int> SetDarknessAsync(AllJoynMessageInfo info, uint value)
        {
            darkness = value;

            Task<int> task = new Task<int>(() =>
            {
                return AllJoynStatus.Ok;
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:snowzk,项目名称:AllJoynToasterDemo,代码行数:15,代码来源:toasterService.cs

示例9: SetStateAsync

        public IAsyncOperation<relaynodeSetStateResult> SetStateAsync(AllJoynMessageInfo info, int interfaceMemberRelayId, byte interfaceMemberState)
        {
            Task<relaynodeSetStateResult> task = new Task<relaynodeSetStateResult>(() =>
            {
                _hm.SetRelay(interfaceMemberRelayId, interfaceMemberState != 0);
                _relayNodeSignals.RelayStateChanged(interfaceMemberRelayId, interfaceMemberState);
                return relaynodeSetStateResult.CreateSuccessResult();
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:martincalsyn,项目名称:CortanaAllJoynDemo,代码行数:12,代码来源:relayService.cs

示例10: StopAsync

        public IAsyncOperation<SonarStopResult> StopAsync(AllJoynMessageInfo info)
        {
            Task<SonarStopResult> task = new Task<SonarStopResult>(() =>
            {
                Debug.WriteLine("Stop");
                mp.Stop();
                return SonarStopResult.CreateSuccessResult();
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:gloveboxes,项目名称:Windows-IoT-Core-SonarScope,代码行数:12,代码来源:SonarService.cs

示例11:

        // Method to handle calls to the Offboard method.
        IAsyncOperation<OnboardingOffboardResult> IOnboardingService.OffboardAsync(AllJoynMessageInfo info)
        {
            Task<OnboardingOffboardResult> task = new Task<OnboardingOffboardResult>(() =>
            {
                AppData.OnboardingConfigureSsid = null;
                AppData.OnboardingConfigurePassphrase = null;
                AppData.OnboardingConfigureAuthType = (short)OnboardingAuthenticationType.Any;
                AppData.OnboardingConfigurationState = (short)ConfigurationState.NotConfigured;
                return OnboardingOffboardResult.CreateSuccessResult();
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:t-angma,项目名称:Windows-universal-samples,代码行数:15,代码来源:OnboardingService.cs

示例12: handler

        // Method to handle calls to the Connect method.
        IAsyncOperation<OnboardingConnectResult> IOnboardingService.ConnectAsync(AllJoynMessageInfo info)
        {
            Task<OnboardingConnectResult> task = new Task<OnboardingConnectResult>(() =>
            {
                EventHandler handler = ConnectRequestRecieved;
                if (handler != null)
                {
                    handler(new object(), new EventArgs());
                }

                return OnboardingConnectResult.CreateSuccessResult();
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:t-angma,项目名称:Windows-universal-samples,代码行数:17,代码来源:OnboardingService.cs

示例13: GetCurrentStateAsync

        public IAsyncOperation<GarageDoorGetCurrentStateResult> GetCurrentStateAsync(AllJoynMessageInfo info)
        {
            Task<GarageDoorGetCurrentStateResult> task = new Task<GarageDoorGetCurrentStateResult>(() =>
            {
                try
                {
                    return GarageDoorGetCurrentStateResult.CreateSuccessResult(_currentState);
                }
                catch (Exception ex)
                {
                    return GarageDoorGetCurrentStateResult.CreateFailureResult(1);
                }
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:mlinnen,项目名称:HacksterIOWin10IoT,代码行数:17,代码来源:GarageDoorService.cs

示例14: CloseGarageAsync

        public IAsyncOperation<GarageDoorCloseGarageResult> CloseGarageAsync(AllJoynMessageInfo info)
        {
            Task<GarageDoorCloseGarageResult> task = new Task<GarageDoorCloseGarageResult>(() =>
            {
                try
                {
                    _driver.OpenGarageDoor(false);
                    return GarageDoorCloseGarageResult.CreateSuccessResult();
                }
                catch (Exception ex)
                {
                    return GarageDoorCloseGarageResult.CreateFailureResult(1);
                }
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:mlinnen,项目名称:HacksterIOWin10IoT,代码行数:18,代码来源:GarageDoorService.cs

示例15: CatAsync

        // Method to handle calls to the Cat method.
        public IAsyncOperation<SecureInterfaceCatResult> CatAsync(AllJoynMessageInfo info, string inStr1, string inStr2)
        {
            IAsyncAction asyncAction = MainPage.Current.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                MainPage.Current.NotifyUser(string.Format("Concatenation request recieved for \"{0}\" and \"{1}\".", inStr1, inStr2), NotifyType.StatusMessage);
            });

            Task<SecureInterfaceCatResult> task = new Task<SecureInterfaceCatResult>(() =>
            {
                if (AppData.IsUpperCaseEnabled)
                {
                    inStr1 = inStr1.ToUpper();
                    inStr2 = inStr2.ToUpper();
                }
                return SecureInterfaceCatResult.CreateSuccessResult(inStr1 + inStr2);
            });

            task.Start();
            return task.AsAsyncOperation();
        }
开发者ID:t-angma,项目名称:Windows-universal-samples,代码行数:21,代码来源:SecureInterfaceService.cs


注:本文中的System.Threading.Tasks.Task.AsAsyncOperation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。