|
Is it throwing any error?Can you check if the file is readonly
|
|
|
|
|
No exception is thrown by the Save()-Method, the file is also not "read-only"
|
|
|
|
|
The app.config file is not updated during execution of application,but it would be writing a .xml document in the bin folder with applicationname.exe(Xml configuration File), and each time your file will be updated but not app.config
|
|
|
|
|
Sorry, of course, app.config is not expected to be updated, but I expect that in the bin-directory one of the files ".xx.exe.config" or "xx.vshost.exe.Config" should be updated at least. But none of them is updated.
I', puzzled. What's the purpuse of the Save()-Method?
Thanks for you kind replies
|
|
|
|
|
Hi
In my application, the Main form starts a thread in another class.
In this thread I need to show another form as modeless. If i call it in the thread, the form shows but in a hanged state. no controls are visible and it is in not responding state.
How can i achieve my requirement.
Please help.
Thanks.
|
|
|
|
|
Did you use BackgroundWorkerClass???
|
|
|
|
|
No.
It is a normal class whose object i'm using in mainform
|
|
|
|
|
Hi,
this article[^] deals with Controls and Threads.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
You have to create all your forms on the GUI thread, of which there can only be one in the application.
I suggest you invoke a method back onto the Main Form thread to create the new modeless form.
|
|
|
|
|
I tried calling a delegate.BeginInvoke in the thread for the main form in which i called the new form.show. but same results. the new form is in hanged state.
|
|
|
|
|
BeginInvoke is not needed as the Show is not going to block any threads. Just call MainForm.Invoke with the delegate to show the newForm. eg.
Thread thread = new Thread(new ThreadStart(StartNewThread));
thread.Start();
}
void StartNewThread(){
this.Invoke(new MethodInvoker(this.LaunchForm2));
}
void LaunchForm2(){
Form2 frm = new Form2();
frm.Show();
}
I know as a standalone example my code would be daft, why start a new thread just to invoke back to the original thread, but I assume you are doing some other processing in the secondary thread to make it worthwhile.
|
|
|
|
|
I'm not sure about the best practices where this is concerned. It's not something I would ever do so I haven't investigated and could maybe have some disasterous consequences. A quick test however reveals it works - I'm sure others will comment!
using System;
using System.Threading;
using System.Windows.Forms;
namespace Forms_Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Load += new EventHandler(Form1_Load);
}
private void Form1_Load(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(StartNewThread));
thread.Start();
}
private void StartNewThread()
{
Application.Run(new Form2());
}
}
}
Edit: This MSDN[^] link may be of interest.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
It works, but ugh!
The main message loop that started Form1 will end when that closes, fire any application clean-up code you wrote and leave Form2 orphaned.
It is a bit like firing up another application using Process.Start . Form2 would have to be treated as a separate application and the start thread must do all the usual stuff you need to run, and shut down an application. On the down side, they would reside in the same AppDomain and a crash in either thread would then kill both, also communication between the parts would be a nightmare.
I'm not sure how they manage it, but I guess Office does something similar for Word and Excel etc. where it appears to fire up a new instance of Word for each document, and they can be closed independently, however only one process is running.
Interestingly in the browser world things are moving the other way, eg. Google Chrome runs each tab in a separate Process, so you get one apparent application but multiple processes!
|
|
|
|
|
Agreed - hence the caveats I placed in there.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
You could post an (custom) event that the main form responds to, and let the main form create the modelss window...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread t = new System.Threading.Thread(
new System.Threading.ThreadStart(delegate
{
Form1 frm = new Form1();
frm.ShowDialog();
}));
t.Start();
}
That seems to work for me.
|
|
|
|
|
It may work for you, but it's not going to work in all instances and environments and it WILL produce bugs that are difficult, if not impossible, to track down. The short answer is you just don't put up UI elements on anything other than the UI thread.
|
|
|
|
|
Dave Kreskowiak wrote: it WILL produce bugs
You sure about that? Do you have a concrete example?
|
|
|
|
|
There's no such thing as a "concrete" example of this.
All you have to do is ask around.
|
|
|
|
|
Word on the street, huh? Oooooo....k.
|
|
|
|
|
Ask around HERE. You want the professional experience behind it? Ask around HERE. Don't take just my word for it. Ask everyone with an MVP icon next to their name.
|
|
|
|
|
Ask anyone who have ever done anything with threading.
The most common bug I come across where I work is anything accessing the UI from another thread, either creating stuff, or just calling methods and properties across threads.
It is worth noting that the debug environment runs in a rather safe mode (somehow) and so threading issues rarely show up during development, unless they are really bad. Worse, you cannot step through them easily as the timing of actions on different threads makes a big difference.
In my experience 50% of threading issues break the application on the first time they are run in a release environment. Of the other 50% it depends on the hardware and network environment. We had a threading issue that only came to light a year after release when the end user upgraded their machine. Suddenly one of the threads ran faster (probably off on another core, or just from the faster processor) and the bug climbed out of hiding.
World of pain!
|
|
|
|
|
Bug number 1.
You used ShowDialog which should produce a modal dialog, however it is modeless, due to running on a separate thread. Therefore you can spawn hundreds of these secondary dialogs, oops. Not an execution bug in this case, but clearly a process flow bug. Having said that changing your code to Show doesn't produce any visible form at all.
|
|
|
|
|
Hello,
I try to add OpenFileDialog to my code and i can not.
What to do?
**I develop in console NOT in WindowsForm
|
|
|
|
|
Yes, well a console application is not supposed to have GUI, does it?
|
|
|
|