• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Tasks.Task类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



System.Threading.Tasks.Task类属于命名空间,在下文中一共展示了System.Threading.Tasks.Task类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CreateDB

        /// <summary>
        /// Create the initial database
        /// </summary>
        private void CreateDB()
        {
            var connection = new SqlCeConnection(this.path);

            try
            {
                var eng = new SqlCeEngine(this.path);
                var cleanup = new System.Threading.Tasks.Task(eng.Dispose);
                eng.CreateDatabase();
                cleanup.Start();
            }
            catch (Exception e)
            {
                EventLogging.WriteError(e);
            }

            connection.Open();
            var usersDB =
                new SqlCeCommand(
                    "CREATE TABLE Users_DB("
                    + "UserID int IDENTITY (100,1) NOT NULL UNIQUE, "
                    + "UserName nvarchar(128) NOT NULL UNIQUE, "
                    + "PassHash nvarchar(128) NOT NULL, "
                    + "Friends varbinary(5000), "
                    + "PRIMARY KEY (UserID));",
                    connection);
            usersDB.ExecuteNonQuery();
            usersDB.Dispose();
            connection.Dispose();
            connection.Close();
        }
开发者ID:novaksam,项目名称:CIS499_C-_IM_Package,代码行数:34,代码来源:DBInteract.cs


示例2: Main

        static public void Main()
        {
            Pubnub pubnub = new Pubnub(
                                       publishKey: "pub-c-d8635a25-b556-4267-84c4-a9db379cd66a",
                                       subscribeKey: "sub-c-e809ad42-8bd8-11e5-bf00-02ee2ddab7fe");

            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(
                () =>
                pubnub.Subscribe<string>(
                channel: channel,
                userCallback: DisplaySubscribeReturnMessage,
                connectCallback: DisplaySubscribeConnectStatusMessage,
                errorCallback: DisplayErrorMessage)
            );
            t.Start();

            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                string msg = Console.ReadLine();
                pubnub.Publish<string>(
                    channel: channel,
                    message: msg,
                    userCallback: DisplayReturnMessage,
                    errorCallback: DisplayErrorMessage);
                Console.WriteLine("Message {0} sent.", msg);
            }
        }
开发者ID:NikitoG,项目名称:TelerikAcademyHomeworks,代码行数:28,代码来源:PubnubExample.cs


示例3: OnNavigatedTo

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // 배경화면
            ChangeBackGround();
            Model.StaticVar.PodCastItemsPageBG = this;
            Model.StaticVar.FunScreen = this;
            Model.StaticVar.MusicPlayerHandler = this;

            CategoryName = (string)e.Parameter;
            ViewModel.MainViewModel.feedBoard.InitRefreshSet_Blogs(CategoryName);
            pageTitle.Text = CategoryName;

            var lists = ViewModel.MainViewModel.feedBoard.Blogs;
            LV_Channels.ItemsSource = lists;

            //LV_Channels.ItemsSource = ViewModel.MainViewModel.feedBoard.Blogs;
            // MainViewModel에서 Category 목록을 불러온다.
            //ViewModel.MainViewModel.feedBoard.InitRefreshSet_Blogs(CategoryName);

            // 펀스크린
//             funsScreenMain = new FunScreen.FunScreenMain();
//             funsScreenMain.Width = 1366;
//             funsScreenMain.Height = 768;
//             RootGrid.Children.Add(funsScreenMain);
//             ShowFunScreen();
            // 펀스크린을 시간에 맞추어 띄우기 위함
            onFunScreen = false;
            timer = 0;
            if (task != null)
            {
                task = new System.Threading.Tasks.Task(waitingTimeForFunScreen);
            }
        }
开发者ID:huinalam,项目名称:WinRTRadioRss,代码行数:33,代码来源:PodCastItemsPage.xaml.cs


示例4: Thread

        Thread(IRunnable runnable, ThreadGroup grp, string name)
        {
            _thread = new System.Threading.Tasks.Task(InternalRun);

            this._runnable = runnable ?? this;
            _tgroup = grp ?? _defaultGroup;
            _tgroup.Add (this);
        }
开发者ID:istupakov,项目名称:SharpCifs,代码行数:8,代码来源:Thread.cs


示例5: Run

        public void Run(string configuration, IResultHandler resultHandler)
        {
            Console.WriteLine("Doing work for: " + configuration);

            var t = new System.Threading.Tasks.Task(() => { resultHandler.OnSuccess(); });

            t.Start();
        }
开发者ID:Timxuhj,项目名称:redis.workflow,代码行数:8,代码来源:ThreadPoolTaskHandler.cs


示例6: EmbeddedBulkInsertOperation

		/// <summary>
		/// Create new instance of this class
		/// </summary>
		public EmbeddedBulkInsertOperation(DocumentDatabase database,BulkInsertOptions options)
		{
			this.options = options;
			queue = new BlockingCollection<JsonDocument>(options.BatchSize * 8);
			doBulkInsert = Task.Factory.StartNew(() =>
			{
				database.BulkInsert(options, YieldDocuments());
			});
		}
开发者ID:nberardi,项目名称:ravendb,代码行数:12,代码来源:EmbeddedBulkInsertOperation.cs


示例7: Process

        public override Exchange Process(Exchange exchange, UriDescriptor endPointDescriptor)
        {
            LogStack.Enqueue(new UriExchange { Exchange = exchange, UriDescriptor = endPointDescriptor });

            if (LogTask == null)
                LogTask = System.Threading.Tasks.Task.Factory.StartNew(ProcessLogQueue);

            return exchange;
        }
开发者ID:ojoadeolagabriel,项目名称:TqWorkflow-beta,代码行数:9,代码来源:Log2Producer.cs


示例8: ProcessTimer

		/// <summary>
		///		Procesa los datos
		/// </summary>
		private void ProcessTimer()
		{ // Detiene el temporizador
				objTimer.Stop();
			// Si se debe ejecutar, crea un hilo nuevo
				if (MustExecute())
					{ System.Threading.Tasks.Task objTaskCompiler = new System.Threading.Tasks.Task(() => CallProcess());

							// Arranca el hilo
								objTaskCompiler.Start();
					}
		}
开发者ID:jbautistam,项目名称:CopySolutionsVisualStudio,代码行数:14,代码来源:AbstractProcessScheduler.cs


示例9: Main

       public static void Main()
        {
            // Start the HTML5 Pubnub client
            Process.Start(@"..\..\index.html");

            System.Threading.Thread.Sleep(2000);

            PubnubAPI pubnub = new PubnubAPI(
                "pub-c-35648aec-f497-4d5b-ab3e-8d621ba3794c",               // PUBLISH_KEY
                "sub-c-fb346fbe-8d19-11e5-a7e4-0619f8945a4f",               // SUBSCRIBE_KEY
                "sec-c-M2JmNWIwODMtNDNhYi00MjBlLWI2ZTYtZjExNjA1OTU4ZDBj",   // SECRET_KEY
                true                                                        // SSL_ON?
            );

            string channel = "simple chat channel";

            // Publish a sample message to Pubnub
            List<object> publishResult = pubnub.Publish(channel, "Hello there!");

            Console.WriteLine(
                "Publish Success: " + publishResult[0] + "\n" +
                "Publish Info: " + publishResult[1]
            );

            // Show PubNub server time
            object serverTime = pubnub.Time();
            Console.WriteLine("Server Time: " + serverTime);

            // Subscribe for receiving messages (in a background task to avoid blocking)
            var task = new System.Threading.Tasks.Task(
                () =>
                pubnub.Subscribe(
                    channel,
                    delegate (object message)
                    {
                        Console.WriteLine("Received Message -> '" + message + "'");
                        return true;
                    }

                )
            );

            task.Start();

            // Read messages from the console and publish them to Pubnub
            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                var message = Console.ReadLine();
                pubnub.Publish(channel, message);
                Console.WriteLine("Message {0} sent.", message);
            }
        }
开发者ID:Vyara,项目名称:Telerik-Academy,代码行数:53,代码来源:PubNubStartup.cs


示例10: Service

        public Service(VerifyData data)
        {
            _Key = new object();
            _Data = data;
            _Soin = new SpinWait();

            _Proxy = new Proxy(new RemotingFactory());
            (_Proxy as IUpdatable).Launch();
            _ProxyUpdate = new Task(Service._UpdateProxy, new WeakReference<Proxy>(_Proxy));
            _ProxyUpdate.Start();

            _User = _Proxy.SpawnUser("1");
        }
开发者ID:jiowchern,项目名称:Regulus,代码行数:13,代码来源:Service.cs


示例11: TaskAsync

        public TaskAsync(ITask task, CancellationTokenSource cancellationTokenSource)
        {
            Contract.Requires(task != null);
            Contract.Requires(cancellationTokenSource != null);

            this.cancellationTokenSource = cancellationTokenSource;
            CancellationToken token = cancellationTokenSource.Token;
            sysTask = new System.Threading.Tasks.Task(() =>
            {
                token.ThrowIfCancellationRequested();
                task.Do();
            }, token);
        }
开发者ID:nbouilhol,项目名称:bouilhol-lib,代码行数:13,代码来源:TaskAsync.cs


示例12: getVersionAsync

 private static async System.Threading.Tasks.Task<int?> getVersionAsync(bool checkOnly = false)
 {
     var task = new System.Threading.Tasks.Task<int?>(getVersion);
     if (!checkOnly)
         task.ContinueWith((antecedent) =>
         {
             lock (defaultVersionLock)
             {
                 defaultVersionAsync = antecedent.Result;
             }
         });
     task.Start();
     return await task;
 }
开发者ID:dioptre,项目名称:nkd,代码行数:14,代码来源:NKDC.cs


示例13: Main

        private static void Main()
        {
            // Start the HTML5 Pubnub client
            Process.Start("..\\..\\PubNubClient.html");

            Thread.Sleep(2000);

            var pubNubApi = new PubNubApi(
                "pub-c-4a077e28-832a-4b58-aa75-2a551f0933ef",               // PUBLISH_KEY
                "sub-c-3a79639c-059e-11e3-8dc9-02ee2ddab7fe",               // SUBSCRIBE_KEY
                "sec-c-ZTAxYTk2ZGMtNzRiNi00ZTkwLTg4ZWEtOTMxOTk4NzAyNGIw",   // SECRET_KEY
                true                                                        // SSL_ON?
            );

            string channel = "chat-channel";

            // Publish a sample message to Pubnub
            List<object> publishResult = pubNubApi.Publish(channel, "Hello Pubnub!");
            Console.WriteLine(
                "Publish Success: " + publishResult[0].ToString() + "\n" +
                "Publish Info: " + publishResult[1]
            );

            // Show PubNub server time
            object serverTime = pubNubApi.Time();
            Console.WriteLine("Server Time: " + serverTime.ToString());

            // Subscribe for receiving messages (in a background task to avoid blocking)
            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(
                () =>
                pubNubApi.Subscribe(
                    channel,
                    delegate(object message)
                    {
                        Console.WriteLine("Received Message -> '" + message + "'");
                        return true;
                    }
                )
            );
            t.Start();

            // Read messages from the console and publish them to PubNub
            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                string message = Console.ReadLine();
                pubNubApi.Publish(channel, message);
                Console.WriteLine("Message {0} sent.", message);
            }
        }
开发者ID:vic-alexiev,项目名称:CloudServices,代码行数:50,代码来源:PubNubSender.cs


示例14: ExecuteIndexingWorkOnMultipleThreads

		private void ExecuteIndexingWorkOnMultipleThreads(List<IndexToWorkOn> indexesToWorkOn)
		{
			var threadingTasks = new ThreadingTask[indexesToWorkOn.Count];
			for (int i = 0; i < indexesToWorkOn.Count; i++)
			{
				var indexToWorkOn = indexesToWorkOn[i];
				threadingTasks[i] = new ThreadingTask(() =>
					transactionalStorage.Batch(actions =>
						IndexDocuments(actions, indexToWorkOn.IndexName, indexToWorkOn.LastIndexedEtag)));

				threadingTasks[i].Start();
			}
			ThreadingTask.WaitAll(threadingTasks);
		}
开发者ID:algida,项目名称:ravendb,代码行数:14,代码来源:TaskExecuter.cs


示例15: Main

        static void Main()
        {
            // Start the HTML5 Pubnub client
            Process.Start("..\\..\\PubNub-HTML5-Client.html");

            //System.Threading.Thread.Sleep(2000);

            PubnubAPI pubnub = new PubnubAPI(
                "pub-c-a40489bf-98a7-40ff-87df-4af2f371d50a",               // PUBLISH_KEY
                "sub-c-68236eaa-8bb6-11e5-8b47-02ee2ddab7fe",               // SUBSCRIBE_KEY
                "sec-c-ZmVhNTE4NTgtYWRmYi00NGNjLWIzNjgtZjI1YTU2M2ZkMDU2",   // SECRET_KEY
                true                                                        // SSL_ON?
            );
            string channel = "demo-channel";

            // Publish a sample message to Pubnub
            List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!");
            Console.WriteLine(
                "Publish Success: " + publishResult[0].ToString() + "\n" +
                "Publish Info: " + publishResult[1]
            );

            // Show PubNub server time
            object serverTime = pubnub.Time();
            Console.WriteLine("Server Time: " + serverTime.ToString());

            // Subscribe for receiving messages (in a background task to avoid blocking)
            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(
                () =>
                pubnub.Subscribe(
                    channel,
                    delegate (object message)
                    {
                        Console.WriteLine("Received Message -> '" + message + "'");
                        return true;
                    }
                )
            );
            t.Start();

            // Read messages from the console and publish them to Pubnub
            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                string msg = Console.ReadLine();
                pubnub.Publish(channel, msg);
                Console.WriteLine("Message {0} sent.", msg);
            }
        }
开发者ID:Boyan1912,项目名称:Web-Services-and-Cloud,代码行数:49,代码来源:Program.cs


示例16: Main

        /* 02. Implement a very simple chat application based on some message queue service:
            Users can send message into a common channel.
            Messages are displayed in the format {IP : message_text}.
            Use PubNub. Your application can be console, GUI or Web-based.*/
        static void Main()
        {
            Process.Start("..\\..\\PubNubChatDemo.html");

            System.Threading.Thread.Sleep(2000);

            PubnubAPI pubnub = new PubnubAPI(
                "pub-c-e485b33f-6d32-4410-9cb8-98c61a4a48df",               // PUBLISH_KEY
                "sub-c-44c8865e-0817-11e3-ab8d-02ee2ddab7fe",               // SUBSCRIBE_KEY
                "sec-c-NWQwNjFmY2EtNzljMy00MGU2LTk4YjYtMWQwZThmM2U1Mjcw",   // SECRET_KEY
                false                                                        // SSL_ON?
            );
            string channel = "secret-ninja-channel";

            // Publish a sample message to Pubnub
            List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!");
            Console.WriteLine(
                "Publish Success: " + publishResult[0].ToString() + "\n" +
                "Publish Info: " + publishResult[1]
            );

            // Show PubNub server time
            object serverTime = pubnub.Time();

            Console.WriteLine("Server Time: " + serverTime.ToString());

            // Subscribe for receiving messages (in a background task to avoid blocking)
            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(
                () =>
                pubnub.Subscribe(
                    channel,
                    delegate(object message)
                    {
                        Console.WriteLine("Received Message -> '" + message + "'");
                        return true;
                    }
                )
            );
            t.Start();

            // Read messages from the console and publish them to Pubnub
            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                string msg = Console.ReadLine();
                pubnub.Publish(channel, msg);
                Console.WriteLine("Message {0} sent.", msg);
            }
        }
开发者ID:nkolarov,项目名称:telerik-academy,代码行数:53,代码来源:PubNubChatDemo.cs


示例17: Main

        internal static void Main(string[] args)
        {
            Process.Start("..\\..\\RecieverPage.html");

            System.Threading.Thread.Sleep(2000);

            PubnubAPI pubnub = new PubnubAPI(
                "pub-c-d9aadadf-abba-443c-a767-62023d43411a",               // PUBLISH_KEY
                "sub-c-102d0358-073f-11e3-916b-02ee2ddab7fe",               // SUBSCRIBE_KEY
                "sec-c-YmI4NDcxNzQtOWZhYi00MTRmLWI4ODktMDI2ZjViMjQyYzdj",   // SECRET_KEY
                false);

            string channel = "PublishApp";

            // Publish a sample message to Pubnub
            List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!");
            Console.WriteLine(
                "Publish Success: " + publishResult[0].ToString() + "\n" +
                "Publish Info: " + publishResult[1]);

            // Show PubNub server time
            object serverTime = pubnub.Time();
            Console.WriteLine("Server Time: " + serverTime.ToString());

            // Subscribe for receiving messages (in a background task to avoid blocking)
            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(
                () =>
                pubnub.Subscribe(
                    channel,
                    delegate(object message)
                    {
                        Console.WriteLine("Received Message -> '" + message + "'");
                        return true;
                    }));

            t.Start();

            // Read messages from the console and publish them to Pubnub
            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                string msg = Console.ReadLine();
                pubnub.Publish(channel, msg);
                Console.WriteLine("Message {0} sent.", msg);
            }
        }
开发者ID:HansS,项目名称:TelerikAcademy-homework,代码行数:46,代码来源:Program.cs


示例18: Main

        static void Main(string[] args)
        {
            log("Server started.");

            Server.ConsoleIO.ConsoleCommand consoleIO = new ConsoleIO.ConsoleCommand(system);

            System.Action oAction = new System.Action(run);
            System.Threading.Tasks.Task oTask = new System.Threading.Tasks.Task(oAction);

            oTask.Start();

               while (system.run())
            {
                System.Threading.Thread.Sleep(5000);
            }

            log("Server closed");
        }
开发者ID:MRH4287,项目名称:GameServer,代码行数:18,代码来源:Program.cs


示例19: buttonStart_Click

        private void buttonStart_Click(object sender, EventArgs e)
        {
            this.update_ui("Start Clicked");

            cTokenSource = new System.Threading.CancellationTokenSource();
            var cToken = cTokenSource.Token;

            task = System.Threading.Tasks.Task<int>.Factory
                .StartNew( () => this.GenerateNumbers(cToken), cToken)
                .ContinueWith( t =>
                                   {
                                       this.ts_updateui("TASK: ContinueWith: DONE");
                                       return 1;
                                   })
                ;

            cToken.Register(FormTask.cancelNotification);
        }
开发者ID:saveenr,项目名称:saveenr,代码行数:18,代码来源:FormTask.cs


示例20: Main

        static void Main()
        {
            // Start the HTML5 Pubnub client
            Process.Start("..\\..\\PubnubClient.html");

            System.Threading.Thread.Sleep(2000);

            PubnubAPI pubnub = new PubnubAPI(PUBLISH_KEY, SUBSCRIBE_KEY, SECRET_KEY, true);
            string channel = "chat-channel";

            // Publish a sample message to Pubnub
            List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!");
            Console.WriteLine(
                "Publish Success: " + publishResult[0].ToString() + "\n" +
                "Publish Info: " + publishResult[1]
            );

            // Show PubNub server time
            object serverTime = pubnub.Time();
            Console.WriteLine("Server Time: " + serverTime.ToString());

            // Subscribe for receiving messages (in a background task to avoid blocking)
            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(
                () =>
                pubnub.Subscribe(
                    channel,
                    delegate (object message)
                    {
                        Console.WriteLine("Received Message -> '" + message + "'");
                        return true;
                    }
                )
            );
            t.Start();

            // Read messages from the console and publish them to Pubnub
            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                string msg = Console.ReadLine();
                pubnub.Publish(channel, msg);
                Console.WriteLine("Message {0} sent.\n", msg);
            }
        }
开发者ID:darkyto,项目名称:Web-Services-and-Cloud,代码行数:44,代码来源:ChatStartup.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Tasks.TaskCompletionSource类代码示例发布时间:2022-05-24
下一篇:
C# Threading.Tasks类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap