本文整理汇总了C#中System.Threading.Tasks.Task.Start方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Tasks.Task.Start方法的具体用法?C# System.Threading.Tasks.Task.Start怎么用?C# System.Threading.Tasks.Task.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Tasks.Task
的用法示例。
在下文中一共展示了System.Threading.Tasks.Task.Start方法的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();
}
示例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);
}
}
示例3: 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();
}
示例4: 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();
}
}
示例5: 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);
}
}
示例6: 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");
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: 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);
}
}
示例10: 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);
}
}
示例11: 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");
}
示例12: 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);
}
}
示例13: Main
static void Main(string[] args)
{
var myIp = GetExternalIp();
// Start the HTML5 Pubnub client
Process.Start(@"..\..\..\PubNub-HTML5-Client.html");
System.Threading.Thread.Sleep(2000);
Pubnub pubnub = new Pubnub(
"pub-c-4331b990-8629-4f47-9669-51f0e2ee9c9d", // PUBLISH_KEY
"sub-c-bfd2fbba-0428-11e3-91de-02ee2ddab7fe", // SUBSCRIBE_KEY
"sec-c-NDExYTBlYjUtM2QyYS00YTJiLWExNDItM2Y5NDQ2ZjA1N2Uy", // SECRET_KEY
"", // CIPHER_KEY
true // SSL_ON?
);
string channel = "ninja-channel";
// Publish a sample message to Pubnub
pubnub.Publish<string>(channel, "", DisplayReturnMessage);
// Show PubNub server time
pubnub.Time<string>(DisplayReturnMessage);
//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<string>(
channel,
DisplayReturnMessage,
DisplayConnectStatusMessage
)
);
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<string>(channel, myIp + " : " + msg, DisplayReturnMessage);
Console.WriteLine("Message {0} sent.", msg);
}
}
示例14: btnMaster_Click
private void btnMaster_Click(object sender, EventArgs e)
{
List<Form> SubForms = new List<Form>();
//Action<Form, Form> AddForm = (v, f) => { v = f; SubForms.Add(v); };
Action<Picasso.MakeForm, Picasso.AssignForm> NewForm =
(Construct, AssignToVar) =>
{
Form f = Construct();
SubForms.Add(f);
this.AddOwnedForm(f);
f.Owner = this;
AssignToVar(f);
};
M = new Master(ImgPath, NewForm, this);
//int ChildrenCount;
Watch = new Stopwatch();
Action A = M.GenerateChildren;
System.Threading.Tasks.Task T = new System.Threading.Tasks.Task(A);
//System.Threading.Thread Th = new System.Threading.Thread(new System.Threading.ThreadStart(A));
Watch.Start();
T.Start();
}
示例15: CorrectCaseTableNames
private void CorrectCaseTableNames(object sender, EventArgs e)
{
try
{
var task = new System.Threading.Tasks.Task(() =>
{
OutputPane.WriteMessageAndActivatePane("Correcting the case of table names...");
var finder = new CorrectCaseTableFinder();
finder.CorrectCaseAllTableNames();
OutputPane.WriteMessageAndActivatePane("Correcting the case of table names...done");
});
task.Start();
if (task.Exception != null)
throw task.Exception;
}
catch (Exception ex)
{
OutputPane.WriteMessage("Error correcting table name case: {0}", ex.Message);
}
}