| |

VerySource

 Forgot password?
 Register
Search
View: 680|Reply: 3

A question about threads

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-13 11:00:01
| Show all posts |Read mode
Please look at the following code: When you execute this program, I did not call the work () method. What is going on? What should be done if it is resolved? Thank you!

class Class1
{
[STAThread]
static void Main (string [] args)
{
Thread currentThread = Thread.CurrentThread;
Thread workThread = new Thread (new ThreadStart (Work));
Ranch
}

static void Work ()
{
bool ishasTxt;
if (File.Exists ("D:\\files.txt"))
{
ishasTxt = true;
}
else
{
ishasTxt = false;
}
StreamWriter sr = new StreamWriter ("D:\\filesOne.txt", ishasTxt);
sr.WriteLine ("this is my file");
sr.WriteLine ("I can write ints {0} or floats {1}, and so on.", 1, 4.2);
sr.Close ();
}
}
Reply

Use magic Report

0

Threads

32

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-4-11 13:00:01
| Show all posts
workThread.Start ();
Reply

Use magic Report

0

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-11 13:30:01
| Show all posts
1 sentence missing:
workThread.Start ();
Reply

Use magic Report

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-11 17:30:01
| Show all posts
Okay, thank you all. I added it and it's ready to execute.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list