|
I used these techniques you told me about ,it may work in other applications but it my code it didnt. I used another thread to show form2 from form1 but i didnt work because i am filling form2 from form1 class and if i make another thread i cant fill form2 from form1 class.
Anyways...I am using this technique to avoid the from freezing when i start the application because i have a very long process consumes 2 mins, the form in this duration freezes and stop me to do anything, if you can help me to give another technique i will appreciate .
Thanx alot .
|
|
|
|
|
Ramez Quneibi wrote: I am using this technique to avoid the from freezing when i start the application because i have a very long process consumes 2 mins
Don't use a 2nd thread to start the form. If the form itself is doing lots of work, have the form use a background thread to perform the work, thus keeping the UI thread free. You should never do any large amount of work on the UI thread. If you are, most likely you have designed your application incorrectly.
I recommend launching form2 from form1 using the same thread that's running form1. If form2 is doing lots of work, make form2 start a background thread to do the work.
|
|
|
|
|
what do you mean by background thread ? i put the process inside the button click event in a thread.
<br />
private void button9_Click(object sender, System.EventArgs e)<br />
{<br />
new Thread(new ThreadStart(Search)).Start(); <br />
}<br />
private void Search()<br />
{<br />
}<br />
|
|
|
|
|
Ramez Quneibi wrote: what do you mean by background thread ?
I mean a thread other than the UI thread. You did new Thread(new ThreadStart(Search)).Start() ; that just started a background thread. Don't use a background thread to launch Form2. Launch Form2 from the UI thread. If you need to perform search work on a background thread, that's fine, but don't create a UI from you background thread.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
ok, this works well, thanx alot
|
|
|
|
|
Is it possible to make an exact copy of an instance of an object (not its reference)?
This is what I'd like to achieve:
1 make a copy of an instance at a certain moment to save the state it's in
2 modify the original for a bit
3 replace the original object with the saved one later on
This way I'd like to be able to "recall" the state my object was in at the moment I made a copy. Is this possible without manually constructing a new object of this type and copying all of it's members?
|
|
|
|
|
To do this, you can binary serialize the object. Serialize the object to a memory stream and then deserialize to a new instance. For classes that don't have a CopyTo method, this is pretty helpful. However, the class that you're serializing has to have the Serializable attribute.
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
Actually it is Serializable since it can be stored to disk too. I just had a go with this but I haven't serialized to memory before and for some reason I'm getting a
System.Runtime.Serialization.SerializationException: End of Stream encountered before parsing was completed.<br />
The code looks like this.
Collection<MyOutput> myOutputCollection = new Collection<MyOutput>();
BinaryFormatter bFormatter = new BinaryFormatter();
MemoryStream mStream = new MemoryStream();
OutputData myOutput;
bFormatter.Serialize(mStream, myOutput);
deserializedOutput = (OutputData)bFormatter.Deserialize(mStream);
myOutputCollection.add(deserializedOutput);
mStream.Close();
I'm serializing and deserializing the object, then adding it to a collection, since I'm still using it from the collection once it's added (it's not like I don't need it anymore).
|
|
|
|
|
Before you deserialize, you have to rewind the memory stream back to the initial position.
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
This works, thx
|
|
|
|
|
In short you want something to that gives you an 'undo' feature. I don't like recommending 'design patterns' without looking at several alternatives, but in this case the Memento pattern fits well.
Googling will give you a solid explanation.
Wikipedia has a short code sample:
Memento pattern[^]
|
|
|
|
|
I see the use of the pattern, but it seems this will only work for a single member that defines the state, while I meant the state of the object itself and all of its members... I'm afraid this won't work, but thanks for the info.
|
|
|
|
|
You could do the following:
Make the following changes to your class:
public class MyClass : ICloneable
{
public MyClass(){}
public MyClass(object newInstance)
{
if ( !(newInstance is MyClass) ) throw new Exception...
MyClass instance = (MyClass)newInstance;
}
public object Clone
{
return (object)this;
{
}
Then in your code you would do as follows:
...
MyClass newObject = new MyClass(oldObject.Clone());
Unfortunately, there is no ICloneable<t> and object is all you can pass.
|
|
|
|
|
Wesner Moise has a good blog posting[^] regarding how to clone objects that don't implement ICloneable. He basically uses reflection to invoke the protected MemberwiseClone method.
If you have the source code to this object, I'd just make it implement ICloneable.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Looks interesting, I'll try this out...
|
|
|
|
|
Works perfectly... Thank you.
|
|
|
|
|
I'm doing this using the Clone method of the object. I think there's no universal mechanism for copying objects, so you need to implement this method by your own. If you are working with more types, it is good to use some ICloneable interface.
This is an example:
<br />
public interface ICloneable {<br />
<br />
object Clone();<br />
}<br />
<br />
public class BitmapWithArray : ICloneable {<br />
<br />
public Bitmap bitmap = null;<br />
public int[] array = null;<br />
public ushort someValue = 0;<br />
<br />
public object Clone() {<br />
<br />
BitmapWithArray obj = new BitmapWithArray();<br />
<br />
if (this.bitmap != null)<br />
obj.bitmap = (Bitmap)this.bitmap.Clone();<br />
<br />
if (this.array != null)<br />
obj.array = (int[])this.array.Clone();<br />
<br />
obj.someValue = this.someValue;
}<br />
}<br />
|
|
|
|
|
Why does the cursor moves one tab ahead when i press Ctrl + I key combination?
Thanks,
Pramod
|
|
|
|
|
Uhhmm because you pressed the Ctrl+I key?
If you want a different behaviour, you must program it.
private void richTextBox1_KeyPress( object sender, KeyPressEventArgs e )
{
if ( e.KeyChar == Keys.ControlKey & Keys.I )
{
richTextBox1.Font = new Font( "Arial", FontStyle.Italic );
e.Handled = true;
}
}
|
|
|
|
|
I want to change the Font Style to Italics,
and i have written the following code:
if (e.KeyCode == Keys.B && e.Modifiers == Keys.Control)
{
tbbTextFormatting_ButtonClick(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbBold));
}
else if (e.KeyCode == Keys.I && e.Modifiers == Keys.Control)
{
tbbTextFormatting_ButtonClick(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbItalic));
}
else if (e.KeyCode == Keys.U && e.Modifiers == Keys.Control)
tbbTextFormatting_ButtonClick(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbUnderline));
is something wrong in this code?
the Bold and Underline work fine
but for italics the cursor moves one tab ahead.
Thanks & Regards,
Pramod
|
|
|
|
|
Try this...
if (e.KeyCode == Keys.B && e.Modifiers & Keys.Control != 0)
{
Reformat(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbBold));
}
else if (e.KeyCode == Keys.I && e.Modifiers & Keys.Control != 0)
{
Reformat(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbItalic));
}
else if (e.KeyCode == Keys.U && e.Modifiers & Keys.Control != 0)
Reformat(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbUnderline));
|
|
|
|
|
Still the cursor moves one tab ahead from the current location.
Pramod
|
|
|
|
|
Are you setting e.Handled = true ???
|
|
|
|
|
NO,
When should i set that?
after my code or before that.
Thanks & Regards,
Pramod
|
|
|
|
|
Hi guys,
I need some help, I am working on validation of the product and I was wondering if you guys could give me some suggestions on how to do it. Basically what I intend to do is to have 1 month, 6 months and 12 month product keys. I am having trouble especially figuring out how to monitor the time; what if the user changes time on their system? etc.
Please help
|
|
|
|