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


C# Tasks.Task类代码示例

本文整理汇总了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类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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