|
System.Windows.Forms.Application.Restart();
|
|
|
|
|
Hey guys thanks for helping, I have the following:
* a main form, mainForm (the main application)
* i have a class, myClass
* i have an auxiliary form, auxForm which displays info about a certain process (method in myClass), say downloadData().
When I make a call to downloadData() the first time, auxForm is created and showed as follows:
<br />
class myClass{<br />
AuxForm myAuxForm;<br />
<br />
downloadData()<br />
{<br />
myAuxForm = new AuxForm (this);
myAuxForm .Show();<br />
doDataLoad();<br />
}<br />
<br />
.<br />
.<br />
.<br />
}<br />
This works fine.
However, once the form has been closed, and I make another call to the above method,
I get an error:
<br />
System.ObjectDisposedException was unhandled<br />
Message="Cannot access a disposed object.\r\nObject name: 'TextBox'."<br />
Source="System.Windows.Forms"<br />
ObjectName="TextBox"<br />
Given that its a textbox on the (closed) form causing the problem, it seems that the object myAuxForm, even though closed/disposed, is not reset to null.
(I have tried doing a if(myAuxForm == null) test before instantiating it again, but with no success).
If anyone has advice on how to get around this problem, it would be much appreciated!
For reference, here is the myAuxForm's code (actually called PriceUpdateForm):
<br />
partial class PriceUpdateForm : Form<br />
{<br />
delegate void OutputDisplayCallback(string s, TextBox txtbxOutputTmp);<br />
StockListManager m_slm;<br />
<br />
public PriceUpdateForm(StockListManager slm)<br />
{<br />
InitializeComponent();<br />
m_slm = slm;<br />
m_slm.m_DisplayOutputEvt += new StockListManager.m_DisplayOutEH(DisplayOutputFromThread);
}<br />
<br />
void DisplayOutputFromThread(string s)<br />
{<br />
DisplayOutput(s, txtbxOutput);<br />
}<br />
<br />
<br />
private void DisplayOutput(string s, TextBox txtbxOutputTmp)<br />
{<br />
<br />
if (txtbxOutputTmp.InvokeRequired)
{<br />
OutputDisplayCallback d = new OutputDisplayCallback(DisplayOutput);<br />
this.Invoke(d, new object[] { s, txtbxOutputTmp });<br />
}<br />
else<br />
{<br />
txtbxOutputTmp.AppendText(s + "\n");<br />
if ((s == "Price data update complete.") && (chbxCloseWhenDone.Checked))<br />
this.Hide();<br />
} <br />
}<br />
<br />
<br />
}<br />
In effect, it comes down to "How to make a call to the same form twice?" I think
Many thanks,
Gerry
C# newbie
|
|
|
|
|
Hi,
Actually Problem is occuring due to your custom event.The work around of this problem is
void DisplayOutputFromThread(string s)<br />
{<br />
if(!this.IsDisposed)<br />
{<br />
DisplayOutput(s, txtbxOutput);<br />
}<br />
}
|
|
|
|
|
Wow thanks sam!
Not sure why the object is still in existence (as its been closed) tho?
Thanks again,
Gerry
|
|
|
|
|
Hello,
The question is if you don't whant to hold the Form in memory and make and only hide it.
If jes, you should add a static "GetInstance" method in your auxForm, which creates an instance at first call and returns it, after that instance != null you return that instanc without creating it new.
The problem of your not accurate disposed class, should not be resolved with an workaround, as this will cause memory leeks and very soon Out of memory exceptions if you go on like this!
As Form is IDisposable and Dipsoe will be called at Close, you should override the Dispose method and unregister the eventhandler you added (-=.....).
Hope it helps!
All the best,
Martin
|
|
|
|
|
Thanks Martin thats some great advice!
|
|
|
|
|
|
i have a gif file with me,and want to place that in the from .
i tried with picture box but its doen't animating.
do we have any other controls or techniques to achieve this?
My small attempt...
|
|
|
|
|
Hello,
sujithkumarsl wrote: i tried with picture box but its doen't animating.
PictureBox, works for me.
Bitmap bmAnimated= new Bitmap(@"......\AnimatedPicture.gif"));
this.pbAnimated.Image = bmAnimated;
All the best,
Martin
|
|
|
|
|
Thanks a lot
My small attempt...
|
|
|
|
|
I have to develop this program(using C#):
Make a main program with a form in it, and a DLL to go along with it all.
In the DLL, add a text file and make, using the property box, the text file's property an embedded resource. Then, using reflection (i suppose), have the main program read the test file and post it to a form.
Plzz tell me how can i access that text file. and Is reflection necessary for it?
And how to achieve reflection?
Plzz reply soon
|
|
|
|
|
ya reflection is necessary for accessing any embedded resource. Get the reference of assembly and read your file in stream.
e.g.
System.Reflection.Assembly a=Assembly.GetExecutingAssembly();<br />
textStreame = a.GetManifestResourceStream("MyProject.MyTextFile.txt")));
|
|
|
|
|
I think that this article does exactly what you want:
Understanding Embedded Resources in Visual Studio .NET[^]
IrfanHaleem wrote: and Is reflection necessary for it?
Well, the Assembly class is in the Reflection namespace, so technically, yes. But you don't have to dig around in the data to get the resource, just use the GetManifestResourceStream method in the Application class.
Example:
Assembly me = Assembly.GetExecutingAssembly();
using (StreamReader reader = new StreamReader(me.GetManifestResourceStream("MyApplication.MyTextFile.txt"))) {
MessageBox.Show(reader.ReadToEnd());
}
-- modified at 5:02 Thursday 10th May, 2007
---
single minded; short sighted; long gone;
|
|
|
|
|
hi everybody,
i had created an application in c# now i want it to run in screen server mode how could i acheive it. Please give me some clue if possible send me some code.
|
|
|
|
|
trap the mouse move and key press events
|
|
|
|
|
|
What data type should be good to represent a series of data (string, double) in turns of efficient and ease. In my series, it usually have about 5000 - 10000 values.
say,
JAN FEB MAR APR MAY
200 400 403 202 122
I wanna do some calculation based on a series of value, then emit another series, so I'd like to use a class to represent them. The order of the value pairs does matter as well. Thanks
Hiya, Everybody ^^
|
|
|
|
|
List<string>
List<int>
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Sorry to tell I'm still using VS 2003, without generic support.
I think I'll go for ArrayList to achieve the goal.
Thanks anyway.
Hiya, Everybody ^^
|
|
|
|
|
hai this is srinu.. am working on remoting ..am facing some difficulties while running GUI based applications.. my problem is .. i want to get remote GUI into local machine..clearly i have a dailog box in remote machine ...i want to get that dailog box using remoting into local machine ...can u plz help me .. is it possible to get that remote dailog into local machine.. gerally am getting any kind of text messages form server through remoting.. but am unbale to get dailog box ..can u plz help me to solve this problem..
thanks in advance..
Thanks,
Srinu.
|
|
|
|
|
Hi!
I'm afraid that's not possible with regular remoting.
The whole idea behind remoting is to execute a function an a different machine, no matter if this function is calculating some value, querying a database or showing a dialog.
The problem with showing a GUI on the other machine is that there's nobody at the other machine to operate the GUI.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hai,
Thank u for ur reply ... if u don't mind can u plz suggest me is there any concept is avaiable in C# to get solution for this problem. now am clearly explaining my problem
i have one server and one client . i need to get some forms from the server ... suppose my client machine has one Form having 3 buttons are (load, display result , Enterdata) if cliek the load button it loads some GUI's and then if i click on display result it get's the form from the server, when i click on Enterdata .. it lauch one dailog and it should take some data from the client machine(client will enter data manually) after pressing "OK" buuton it will update data in the server machine .. when ever user reqest that data then it shuld be show the data to user when user cliks the button load ( in client machine form ) ...is this my problem can u plz suggest me any kind of solution for this .. i want to implement this on only C#..thanks in advance..
|
|
|
|
|
Hi,
I have a form as a main form that in this form menues of application located on it. Now I wana to add a login form.I wana this login form show at the first and after we input current data in username and password the second form show.
would you please what should I have to do?????????
thanks
|
|
|
|
|
When the form loads, have it make itself invisible, and then show the login form. If login fails, close. If it succeeds, show the main form.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
I did it. in main form I write this code in from.load event :
this.Hide();
Frm_LogIn_User frm = new Frm_LogIn_User();
frm.ShowDialog(this);
this code correctly work but in the login form in button1.click enevt I write this code :
if (textBox1.Text == "1" && textBox2.Text == "1")
{
Frm_LogIn_User frm = new Frm_LogIn_User();
frm.Dispose(this);
}
this code does not work and I think maybe the code is wrong.
I would appreciate of somebody help me.
thanks
|
|
|
|