|
You can Create your thread function in class and pass
The Parameters to the class Constructor
For Example
<code>
public class Test
{
private string firstName;
private string Lastname;
private string fullName;
public Test(string fn,string ln)
{
firstName=fn;
Lastname=ln;
}
public string FullNameProp
{
get
{
return fullName;
}
}
public void FullName()
{
fullName=firstName + " " + lastName;
}
}
</code>
Then create instance from this class and path FullName Method to ThreadStart
you can access FullNameProp to get the result value
another method you can use Asynchronous Calls
Note:
this code i typed it here directly so review it
MCAD
-- modified at 18:29 Saturday 27th August, 2005
|
|
|
|
|
hi, thx a lot!
can i start the threat like that?
<br />
Thread worker = new Thread(new ThreadStart(FullName));
worker.Start();
why is public void FullName(), fullName, fistName and lastName not static?
cu
|
|
|
|
|
hi now i understood what you mean
here my code...any improvements?
<br />
using System;<br />
using System.Threading;<br />
<br />
namespace MyConsoleThread<br />
{<br />
class ThreadMain<br />
{<br />
[STAThread]<br />
static void Main(string[] args)<br />
{<br />
MyThread thread1 = new MyThread();<br />
Thread[] ta = new Thread[100];
<br />
for (int j = 0; j<10; j++)<br />
{<br />
ta[j] = new Thread(new ThreadStart(thread1.start));
ta[j].Start();
}<br />
<br />
System.Console.ReadLine();<br />
}<br />
}<br />
<br />
class MyThread<br />
{<br />
public int i=0;<br />
public Object lockvar = "";
<br />
<br />
public void start()<br />
{<br />
Monitor.Enter(lockvar);<br />
String mystring = "Thread gestartet ";<br />
i++;<br />
mystring += i;<br />
System.Console.WriteLine(mystring);<br />
Monitor.Exit(lockvar);<br />
}<br />
}<br />
}<br />
|
|
|
|
|
While your code is okay, having a Monitor protect the start function will force each thread to wait until the thread that acquired the Monitor releases it. Which makes running start in a 100 different threads totally useless. You might as well run it in a loop, like
for(int i = 0; i<100; ++i) thread1.start();
The only difference is that, with threads, there is no guarantee as to the order in which each of the 100 threads execute.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Dear ALL,
I want to call an opencv function from C#...(a function from the OpenCV library provided by Intel)
I was wondering if I just call the .dll or is there some sort of installation that has to be done to the library?
Best Regards,
E.A.
|
|
|
|
|
|
Thanks Muhammad,
I have read about P/Invoke...
My problem now is with marshalling the data between the managed and unmanaged code...
The unmanaged function that I want to call has the following input parameter of type CvContourRetrievalMode that takes only 4 values ,either CV_RETR_TREE ..etc
I don't know if it would be correct to use an enum in this case?
Thanks again,
E.A.
|
|
|
|
|
Hi
I'me new to C# and about to finish my first example program. It is a command line program (no gui). What I want to do now is adding a form for configuration values. These values should be written into an xml file and should be read by the program afterwards.
I heard about system.configuration and its read capabilities. But I didn't heard anything about writing to sections.
Now my question: Where can I get tutorials or other informations about writing and reading to/from configuration files?
Thanks and regards Fredy
|
|
|
|
|
|
Thanks alot! This helps.
Have a nice weekend! ;)
|
|
|
|
|
Hi,
I want to encrypt a password and store the encrypted version in the database. then when the user logs in, I want to decrypt the user password and match with the entered password. I read about DESCryptoServiceProvider, but still i am not able to understand it. Can someone send a link of article which is easy to understand/provide a piece of code here. It would be great for me.
Thanks
|
|
|
|
|
Hi,
If you want to store a password in database, I suggest you use a 'One-Way Hash' algorythm.
These are un-reversable encryption algorythms, hence the name one-way. Then you follow these steps to authenticate your users:
1. User Registers, Username and Hashed Password are stored in DB.
2. User types in Username and Password. P = password
3. The Software encrypts the Users Password with a One-Way Hash. P1 = Hash(P)
4. The Software queries the database and finds the password of the user (Storing Hashed in the database). P2 = database_pass
5. If the Hashed Pass in the DB and Hashed Pass the user typed in Match, Allow Login. If P1 == P2 then Login else Fail (remeber P1 = Hash(P))
Try this code to generate a one-way hash of a password.
-------------------------------------------------------------------------------
private Byte[] GetByteArray( String originalString )
{
Char[] charArray = originalString.ToCharArray();
Byte[] byteArray = new Byte[charArray.Length];
for ( int i=0; i<byteArray.Length; i++ )
{
byteArray[i] = Convert.ToByte( charArray[ i ] );
}
return byteArray;
}
/// <summary>
/// Creates a one-way SHA1 hash of the pt string
/// </summary>
/// <param name="pt">Plaintext to Hash</param>
/// <returns>Ciphertext string</returns>
public string Hash(string pt)
{
//Implement SHA1 Hashing Algorythm (40 Bytes / 320 bits)
byte[] data = new byte[40];
byte[] hash = new byte[40];
while (pt.Length % 4 != 0) pt += "g";
data = Convert.FromBase64String(pt);
SHA1 sha = new SHA1CryptoServiceProvider();
hash = sha.ComputeHash(data);
return Convert.ToBase64String(hash);
}
-------------------------------------------------------------------------------
Thanx!
Dave Shaw
History admires the wise, but elevates the brave. - Edmund Morris
|
|
|
|
|
Thanks a lot
|
|
|
|
|
Hi - I'd like to dynamicaly move a button during runtime.
I've tried changing the control's Control.Location.X and .Y but get the error:
Cannot modify the return value of 'System.Windows.Forms.Control.Location' because it is not a variable.
Is there a way to move a control at run time?
Thanks, mutty
|
|
|
|
|
How about Control.Left or control.Top?
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
|
Well and if you want to know why you cannot change it: open reflector and see that the Location property returns the following:
return new Point(this.x, this.y);
So it is returning a new point object. If you anyway want to change the location of the control using the Location property you should feed it a new Point :
Control.Location = new Point(X,Y);
regards,
Gidon
|
|
|
|
|
Is there a way to find out the Windows version of a machine on the network in C#? I just want the Windows version (9x, XP, etc) and which service pack.
|
|
|
|
|
Take a look at WMI -- you can access it with script (VBScript, JScript, Python, Ruby, etc.) or even directly from C# with a little interop. Check out Scriptomatic[^] and look around that same vicinity of TechNet for more WMI information.
Matt Gerrans
|
|
|
|
|
i need to create a 'window dialog' in .showdialog() for user data input.
i can made it using window form or a component, but i've to do a choose.
What is better?
|
|
|
|
|
How can i count the number of lines in a string also the number of bytes in a string?
|
|
|
|
|
The number of lines in a string is the number of occurrences of Environment.NewLine + 1 . As the string class does not contain a method to count substrings you would probably have to run a for-loop over each char in the string and count.
The number of bytes of a string should be string.Length * sizeof(char) .
|
|
|
|
|
To Count line in string
Regex rx=new Regex(Environment.NewLine);
MatchCollection mc=rx.Matches(textBox1.Text);
int lineCount=mc.Count;
Note:if the last two chars of string is not Environment.Newline
the line count will be decreased by 1 so you can check
that last two chars in the string is Environment.NewLine
If not add it
To Get the bytes in string use Encoding class
and select Encoding Format you work with
For Example
int cb=Encoding.UTF8.GetByteCount(textBox1.Text);
MCAD
-- modified at 9:40 Saturday 27th August, 2005
|
|
|
|
|
Just to make publicity... :-P
Some files can be Mac and Linux files, and they can have different "NewLines"... Look at this program I made, get the source code if you want!
http://www.sulfurmidis.com/sulfursoft/software/tfc.html[^]
Darth_Sulfur (Sulfurik)
http://www.sulfurmidis.com
http://www.sulfursoft.tk
ftp://tsfc.ath.cx
http://tsfc.ath.cx
hotline://tsfc.ath.cx
|
|
|
|
|
The easiest way of counting the number of line breaks would be to remove them from the string and then check the difference in size:
lines = 1 + ((Len(text) - Len(text.Replace(Environment.NewLine, string.Empty))) / Len(Environment.NewLine));
---
b { font-weight: normal; }
-- modified at 11:28 Saturday 27th August, 2005
|
|
|
|