Visual studio runs old code

  • Christian Chat is a moderated online Christian community allowing Christians around the world to fellowship with each other in real time chat via webcam, voice, and text, with the Christian Chat app. You can also start or participate in a Bible-based discussion here in the Christian Chat Forums, where members can also share with each other their own videos, pictures, or favorite Christian music.

    If you are a Christian and need encouragement and fellowship, we're here for you! If you are not a Christian but interested in knowing more about Jesus our Lord, you're also welcome! Want to know what the Bible says, and how you can apply it to your life? Join us!

    To make new Christian friends now around the world, click here to join Christian Chat.
W

wwjd_kilden

Guest
#1
Sooo, google is confusing as usual.

I am programming in Visual Studio as I am trying to get used to C# again.
I am making a basic program with various nonsense and running code now and then to see what happens.
Problem is, now it won't run the new code.

I tried Save all
I tried Rebuild
I tried restarting Visual Studio
.... no luck.

It can't be because of a bug, because even though I am the master of bugs, it won't even display the simple
Console.WriteLine("TEST Stuff..."); that I added as a debug test at the start of the code. It writes "simple properties", which is what my code said before I changed and saved and rebuilt it.

Ideas on why this is happening and how to avoid it?
(Why didn't they teach us this stuff at school? :/ )

We didn't really learn much about debugging/ testing. Are there any good alternatives to actually running the code to see if it works?

public static void Main()
{
Console.WriteLine("TEST Stuff...");

Person person = new Person();

person.present();
person.doSomething();
Console.ReadLine();
}
 
A

Abing

Guest
#2
Wish I could help...
 
W

wwjd_kilden

Guest
#4
Not yet. You know of any good ones?

(It did fix itself eventually, but problem is I never know whether or not it runs my newest code)
 
S

Siberian_Khatru

Guest
#5
kilden, you really need to stop asking questions I don't know the answer to. Lol. (Please don't take that seriously; I hope you find some help on this.)
 
Y

Yehoyada

Guest
#7
What version of VS are you using?

The next time this happens, try opening up your solution properties under the Debug Menu. If you are using the Local IIS Web Server, change the IIS Server Settings to use the Visual Studio Development Server.

It's worth a try.

God's peace,
Yehoyada
 
W

wwjd_kilden

Guest
#8
2010

Ok, thanks.
I haven't been using it for a few weeks but I'll try that next time it happens :)
 

JasonNosneh

Senior Member
Aug 2, 2015
110
4
18
#9
you can get the 2015 community edition of visual studio free so not sure why you would want to 2010 version

https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx

There is nothing wrong with visual studio switching to a new IDE is silly suggestion. It is definitely the best C# dev tool in existence. Also, this doesn't have anything to do with IIS server because it is a console application not a web application.

First there is nothing wrong with the code -- if it builds without error then it should work. I am assuming you defined Person class in another file or just didn't show the code. When you run the project does the console window open? Honestly, you are not providing enough information for anyone to help you. The first rule of being a good developer is being able to diagnosis the problem by first providing as much detail as possible. As a last resort, maybe start over and just create a new console app project from scratch and copy the code.
 
W

wwjd_kilden

Guest
#10
I know I didn't provide all the code, but my question was about why the new code wouldn't run at all.
(So I removed the code I had added and just used the writeLine to see if it was noticing changes at all, and it didn't.
Now I deleted that bit of code and remade the creator and an entry class, so now it does what it was supposed to :) yay
 
Y

Yehoyada

Guest
#11
I know I didn't provide all the code, but my question was about why the new code wouldn't run at all.
(So I removed the code I had added and just used the writeLine to see if it was noticing changes at all, and it didn't.
Now I deleted that bit of code and remade the creator and an entry class, so now it does what it was supposed to :) yay
Well done, wwjd_kilden.

I am happy that you were able to figure it out on your own. Sometimes, that's all we can do.

Blessings,
Yehoyada
 
W

wwjd_kilden

Guest
#12
so, just for the sake of not creating more threads:

How do I go about closing a streamwriter that is used by multiple threads ?
(Do I have to close it? it writes just fine to the file even if I don't)
The way shown underneath causes an immediate crash. If i remove the writer.close method everything works.

-----
private static Mutex mutex = new Mutex();
private static string filePath = "output.txt";
private static StreamWriter writer = new StreamWriter(filePath);


private void startThreadsButton_Click(object sender, EventArgs e)
{
Thread trd;

MessageBox.Show("...", MessageBoxButtons.OK, MessageBoxIcon.Warning);

for (int i = 0; i < 10; i++) {

trd = new Thread(() => threadTask(i + 1));
trd.Start();
}

writer.Close(); //*
}


private void threadTask(int id)
{
mutex.WaitOne();

this.Invoke((MethodInvoker)(() => listBox1.Items.Add("Starting thread " + (id + 1))));
this.Invoke((MethodInvoker)(() => listBox1.Refresh()));

Random rnd = new Random(); int ms = rnd.Next(1000);
string info = "Thread id:" + id + "| Sleep time in ms:" + ms;

Thread.Sleep(ms);
writeToFile(info);

this.Invoke((MethodInvoker)(() => listBox1.Items.Add("Finishing thread " + id + " | Sleep time:" + ms )));
this.Invoke((MethodInvoker)(() => listBox1.Refresh()));

mutex.ReleaseMutex();
}

private void writeToFile(string info)
{
writer.WriteLine(info);
writer.Flush();
}

and: Why on earth don't I get threads ranging from 1-10, but two threads of the same nr?

Thread id:2| Sleep time in ms:691
Thread id:11| Sleep time in ms:434
Thread id:4| Sleep time in ms:734
Thread id:3| Sleep time in ms:30
Thread id:9| Sleep time in ms:584
Thread id:8| Sleep time in ms:219
Thread id:5| Sleep time in ms:466
Thread id:8| Sleep time in ms:515
Thread id:8| Sleep time in ms:759
Thread id:9| Sleep time in ms:251