Menu

[r40]: / trunk / WhatsappClient / Classes / ThreadedMethod.cs  Maximize  Restore  History

Download this file

65 lines (57 with data), 1.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* by Swen Kooij aka Kirk - swenkooij@gmail.com
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.ComponentModel;
/// <summary>
/// Makes starting a method in a seperated thread just a little bit easier.
/// </summary>
class ThreadedMethod
{
/// <summary>
/// Holds an instance of the ParametizedThreadStart delegate in case the method has paramters.
/// </summary>
private ParameterizedThreadStart pStart;
/// <summary>
/// Holds an instance of the ThreadStart delegate in case the method doesn't have any parameters.
/// </summary>
private ThreadStart tStart;
/// <summary>
/// Class constructor if you want to start a method with parameters.
/// </summary>
/// <param name="_pStart">The name of the method, all parameters are object. See MSDN documentation on ParameterizedThreadStart.</param>
public ThreadedMethod(ParameterizedThreadStart _pStart)
{
pStart = _pStart;
}
/// <summary>
/// Class constructor if you want to start a method without parameters.
/// </summary>
/// <param name="_tStart">The name of the method that needs to be started in a seperated thread.</param>
public ThreadedMethod(ThreadStart _tStart)
{
tStart = _tStart;
}
/// <summary>
/// Starts the method in a new thread.
/// </summary>
public void Start()
{
if (pStart == null)
{
Thread Th = new Thread(tStart);
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
Th.Start();
}
else
{
Thread Th = new Thread(pStart);
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
Th.Start();
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.