|
Hello,
I am having a form based application. In constructor of main application form it initiates a thread for hardware.
Now the hardware raises a event which is listned back in to the main form itself. Here i want to create a form which should be child of main form.
I am doing
frmSerialKeyInsert mFrmSerialKeyInsert ;
mFrmSerialKeyInsert = new frmSerialKeyInsert();
frmMDIMain.mFrmSerialKeyInsert.MdiParent = this;
But i got exception "controls create on one thread cannot be parented to a control on different thread"
How to solve this problem??
|
|
|
|
|
Look for Control.InvokeRequired and Control.Invoke()
only the main thread should access Controls.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I have some problem about RMAN and C#.I don't understand command of RMAN that provide backup file as
i. data files
ii. control files
iii. redo log files
iv. archived log files
Could you tell me about how to use this 4 commands.
And I can't write C# that control RMAN backup file
Help me please. Thank you very much.
|
|
|
|
|
I'm trying to handle the exception in my project. If the exception raised in same thread, I can handle it by using Try/Catch statement... but I'm not sure how to handle in different thread.....
I have one window application called "WindowsApplication1" and one class library called "ClassLibrary1". I added "ClassLibrary1" to "WindowsApplication1" as a reference.
In WindowApplication1, I have the following code.
delegate void action2();<br />
private void button1_Click(object sender, EventArgs e)<br />
{ <br />
try<br />
{<br />
ClassLibrary1.Class1 obj = new ClassLibrary1.Class1 ();<br />
action2 del = new action2 (obj.foo);<br />
del.BeginInvoke( callback, del);<br />
}<br />
catch ( Exception ex )<br />
{<br />
MessageBox.Show (this,ex.Message);<br />
}<br />
}<br />
private void callback(IAsyncResult a)<br />
{<br />
try<br />
{<br />
action2 a2 = (action2)a.AsyncState;<br />
a2.EndInvoke (a);<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show (this, ex.Message);<br />
}<br />
}<br />
In ClassLibrary1.Class,
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
<br />
namespace ClassLibrary1 {<br />
public class Class1 {<br />
public void foo()<br />
{<br />
throw new Exception ("Why!!!");<br />
}<br />
}<br />
}<br />
When I run the application with "Control + F5" (without debugging), I got the messagebox ""Why!!!"" as the exception shown.
but when I run the application with "F5" (with debugging), I don't get the messagebox and Try/Catch statement from Form1 doens't work anymore..
So, How to handle the exception in different thread??
Any idea would be greatly appreciated. Let me know if you are not clear what I meant..
Thanks in advance.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
I need to set the text on various form controls(textbox,label,buttons, etc) across threads.
Right now, I have one method per control. Below is my SetButtonText method.
private delegate void SetButtonTextCallback(System.Windows.Forms.Button tBox, string text);
private void SetButtonText(System.Windows.Forms.Button tBox, string text)
{
if (tBox.InvokeRequired)
{
SetButtonBoxCallback d = new SetButtonTextCallback(SetButtonText);
this.Invoke(d, new object[] { tBox, text });
}
else
{
tBox.Text = text;
}
}
Is it possible to have a generic method that I can pass the control and the text. So the call would look like:
SetControlText(button1,"foo");
or
SetControlText(label3,"bar");
|
|
|
|
|
Just use System.Windows.Forms.Control instead of System.Windows.Forms.Button. Every Control has a Text property.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Wow! So easy easy, I missed it!
Thanks!
|
|
|
|
|
I have written a class that allows our application to manipulate the default printer of a workstation. The code below works perfectly on WinXP but not on Win2000...
ManagementObjectSearcher search = new ManagementObjectSearcher("select deviceid from win32_printer where default = TRUE");
Any suggestions?
|
|
|
|
|
Hi, everyone.
I am doing image alignment which compare the difference between two similiar screenshots and aligned the second image to first one. Now, I am able to solve the difference. For two similiar images, I can get the difference between them. But I am stucked at how to do the alignment. any suggests?
Thank you
|
|
|
|
|
I have a Grid View. Here I have a column "Active". I attached this GridView to objectDataSource. In database this field has true or false value.(1 or 0). But in Grid View I want to show that if this field has value 1 in database the value for this column should show "Yes" but if the value of this field is 0 in data base the The GridView should show "No".
How can I do that.
seema
|
|
|
|
|
Please don't cross post
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
Hide the Active column on the gridview
Create a new column not bound to a db field.
Use the ItemDataBound event to change the new column based on the contents of the hidden column
|
|
|
|
|
Hello,
I am reading values from an Access Database with an OleDbDataReader. I am using the following command:
myCommand.CommandText =
"SELECT FolderName, SecurityGroupName " +
"FROM tblFolderSecurityTemplateInternal";
I am then putting this data into a dynamic array. Here is my problem. I need a way to have the DataReader output to a multi dimensional array. MyReader only takes one value in the array: Ex: subitems1[j,k] = myReader1[j].ToString(); Ultimately, I want to set subitems[j] = to a new variable called FolderNm and subitems[k] = to a new variable called SecurityGroupNm.
OleDbDataReader myReader1;
myReader1 = myCommand.ExecuteReader();
int nFields1 = myReader1.FieldCount;
while (myReader1.Read())
{
// Create an array of subitems
String[] subitems1 = new String[nFields1];
for (int j = 0; j < nFields1; j++)
{
for (int k = 0; k < 2; k++)
{
subitems1[j, k] = myReader1[j].ToString();
}
}
myReader1.Close(); //Close the reader.
|
|
|
|
|
I may be wrong but, aren't you just duplicating the functionality of a DataSet ? I can't believe the increased overhead would be that dramatic.
|
|
|
|
|
Please don't repost questions this quickly. It's plain rude.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
My application has one MDIparent (say MDIparent.cs) and a tool form (say mainform.cs).
A text box in the mainform.cs takes some strings as input and displays the resulting data on the form. There are thousands of strings that can be entered in the input field that give different data for that particular string.
After entering my first string in the mainform, i open a "new" form in the MDIParent (File-->New) to give me another window of form so that i can calculate data for a different string.
However, when i do that, the application seems to be over-writing the data of the new window onto the first form and vice versa.
My goal is to keep keep the data different for different strings, separate.
Is it a problem with MDIParent or form?
Can anyone give me an idea how can i make sure that the form only subscribes to the proper event on itself alone?
Thanks
|
|
|
|
|
Hello,
I am reading values from an Access Database with an OleDbDataReader. I am using the following command:
myCommand.CommandText =
"SELECT FolderName, SecurityGroupName " +
"FROM tblFolderSecurityTemplateInternal";
I am then putting this data into a dynamic array. Here is my problem. I need a way to have the DataReader output to a multi dimensional array. MyReader only takes one value in the array: Ex: subitems1[j,k] = myReader1[j].ToString(); Ultimately, I want to set subitems[j] = to a new variable called FolderNm and subitems[k] = to a new variable called SecurityGroupNm.
OleDbDataReader myReader1;
myReader1 = myCommand.ExecuteReader();
int nFields1 = myReader1.FieldCount;
while (myReader1.Read())
{
// Create an array of subitems
String[] subitems1 = new String[nFields1];
for (int j = 0; j < nFields1; j++)
{
for (int k = 0; k < 2; k++)
{
subitems1[j, k] = myReader1[j].ToString();
}
}
myReader1.Close(); //Close the reader.
|
|
|
|
|
Hello,
How can I throw event in unmanaged code (cpp) and catch it in managed code (c#) ?
thanks
|
|
|
|
|
Can the C++ code be compiled as C++/CLI? If so, you can define events there like any other managed language.
|
|
|
|
|
you can pass a delegate to unmanaged code, accept it as a function pointer and call it
when you feel like it.
The delegate could then invoke the event using purely managed code.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
With the help of Yesterday`s discussion[^] and this[^] I worked am getting all the type in system.Windows.Forms
Code:
<font>AssemblyName name = new AssemblyName("System.Windows.Forms");
name.CultureInfo = new System.Globalization.CultureInfo("");
name.SetPublicKeyToken(new byte[] {0xb7, 0x7a, 0x5c, 0x56, 0x19, 0x34, 0xe0, 0x89});
name.Version = new Version(2, 0, 0, 0);
Assembly a = Assembly.Load(name);
Type[] types = a.GetTypes();
foreach (Type t in types)
{
if (t.Namespace == "System.Windows.Forms")
listBox1.Items.Add(t.ToString());
}
MessageBox.Show(listBox1.Items.Count.ToString());
</font>
I didnt Understand the meaning of
<br />
name.SetPublicKeyToken(new byte[] {0xb7,0x7a, 0x5c, 0x56, 0x19, 0x34, 0xe0, 0x89});<br />
Can you Explain This
Thanks & Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
When signing assemblies a private and public key are generated by the company distributing the assembly. The company keeps the private key in a secure location. The public key is sent along with the assembly. When the company signs an assembly with the private key, third party users can then use the public key to verify that the assembly has not changed. Basicaly it allows users to detect if someone has tampered with the assembly.
Now, assemblies have four pieces of information to describe their full name. They are Name, Version, Culture, and PublicKeyToken. The PublicKeyToken is the public key which is used to validate that the assembly has not changed.
Now, it is possible to change the assembly and simply sign it will a different private key and update the PublicKeyToken appropriately. But in this case, you application is typically tied to the assembly using the full name (which include the correct public key). So in this case your application won't open the assembly because the public key is not correct.
So, long story short. If you excluded the public key then the assembly would still load, but then someone could drop in a "hacked" version of the assembly and your application would happily load it.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks and regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
I have one more problem
How can I distinguish controls in any namespace / dll
Thanks & Regards
Amar Chaudhary
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
You're going to have to explain what you mean by this. What do you mean by "distiguish"?? And in "any namespace"?? What are you trying to do??
|
|
|
|