|
hm..in this case, the "new" instance is startet before the old is killed.
i'm not sure right now if this can be a problem, but i'd prefer to avoid this..
|
|
|
|
|
buchstaben wrote: hm..in this case, the "new" instance is startet before the old is killed.
Yes - Which is also how Application.Restart works too. (I naturally assume that you know this already)
buchstaben wrote: i'm not sure right now if this can be a problem, but i'd prefer to avoid this..
Why? You were happy to use Application.Restart if it were available to you.
|
|
|
|
|
Colin Angus Mackay wrote: Why? You were happy to use Application.Restart if it were available to you.
I were happy because I didn't know the behaviour
However, it works now.
|
|
|
|
|
Call Main again - but don't forget to include an exit condition somewhere otherwise you'll end up in an infinite loop.
|
|
|
|
|
calling main again would result in two running applications.
there are some background activities running in my app. in the main thread somewhere i'm waiting until all backgound processes finished. but if a certain time elapsed, i dont want to wait anymore and restart application, since there might be a hangup in any background process.
|
|
|
|
|
buchstaben wrote: calling main again would result in two running applications.
No it wouldn't. It would be the same application but the starting point is called for a second time.
buchstaben wrote: there are some background activities running in my app. in the main thread somewhere i'm waiting until all backgound processes finished. but if a certain time elapsed, i dont want to wait anymore and restart application, since there might be a hangup in any background process.
I'm not sure you are using the word process correctly here. Do you mean process as in a ancillary application (which would be the correct use of the word) or process as in another thread?
If you mean process as in other processes (ancillary applications) then just kill the processes.
If you mean process as in another thread then kill the threads.
|
|
|
|
|
i meant process in the thread context.
so i'm gonna kill all running background threads and return to main.
thanks.
|
|
|
|
|
buchstaben wrote: calling main again would result in two running applications.
No it wouldn't. You're not actually going to create a new process here - why do you think Main would behave differently to any other method, none of which results in a new process?
buchstaben wrote: there are some background activities running in my app. in the main thread somewhere i'm waiting until all backgound processes finished. but if a certain time elapsed, i dont want to wait anymore and restart application, since there might be a hangup in any background process.
This sounds like you are getting a bit confused architecturally. Don't restart the application - just kill the threads (be aware that this is really frowned upon though).
|
|
|
|
|
Pete O'Hanlon wrote: This sounds like you are getting a bit confused architecturally. Don't restart the application - just kill the threads (be aware that this is really frowned upon though).
just killing the threads wouldn't help, since i must ensure each background thread runs every main run.
a main run simply covers invoking all registered background threads, starting a timer and wait for the timer's and threads' ready-events. if both, timer and all threads are ready, start a new main run.
if timer is ready since x seconds, (assuming non-expected exception) the app should ignore the background threads' states and stop current main run. now all background threads have to be killed and invoked again. that's actually what my goal is.
architecturally this should be ok, shouldn't?
|
|
|
|
|
It's me again,
I have two check box. I want to decide on of it enable/disable state depend on other.
Say first one is enable, then the second also enable. If the first disable then the second also disable.
I try to use state change of the first, as follows.
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
checkBox2.Enabled = true;
}
In form load I disable the second checkbox. Say I check the first one and un-check it again. At that time the second checkbox is not disable again. What should I do
Thanks
I appreciate your help all the time...
Eranga
|
|
|
|
|
1) Assign the same event handler for both the chack boxes chaeckedChanged event.
2) checkBox1.Enabled = checkBox2.Enabled ^= true;
But the question is if the first is disabled and you want the second also to be disabled how will you enable them again since you cannot check them again ??
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
Beacuse you didn't check the condition for the state of checkbox when you click on it.
So when you click on checkbox1 it will enable the checkbox2 and then it will never be set disable by you.
With Regards
Yogesh Agarwal
|
|
|
|
|
Just need a logic as follows.
if( !checkBox2.Enabled )
checkBox2.Enabled = true;
else
checkBox2.Enabled = false;
Hope it is fine, and sorry for disturbing.
Thanks for all replay
I appreciate your help all the time...
Eranga
|
|
|
|
|
The statement checkBox2.Enabled ^= true does the same thing.
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
Hi,
you want Checkbox.EnabledChanged event
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
checkBox2.Enabled = this.checkbox1.Enable;
}
Never trouble trouble until trouble troubles you.
|
|
|
|
|
Hi all,
On a specified registry(actually on a sub key of the registry), I want to copy all there settings to a file. And later I want to restore that file setting too. How can I do that.
Thanks
I appreciate your help all the time...
Eranga
|
|
|
|
|
1) Right click te key and click export.
2) To restore double click the file you exported before.
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
Yes, its true
But I want to do it through my code. When a user click a button I want to make a backup and so on
I appreciate your help all the time...
Eranga
|
|
|
|
|
use Microsoft.Win32.Registry and get the root RegistryKey which you want to backup. having this, loop recursibly over registryKey.GetSubKeyNames and get the corresponding values. now you can store this as xml.
|
|
|
|
|
|
|
Hello Everybody,
I have developed an application in which i have used Code 39 font and Embedded that in my application now whenever i run that application on XP that runs and give specified output.
Now when i tested it on Vista than i am unable to get the output in Code 39 font its just give output in normal font.
|
|
|
|
|
I haven't got a Vista box here at work to test on but it could depend on how you're getting the font. This is the method I use...
[DllImport("gdi32.dll")]
private static extern IntPtr AddFontMemResourceEx(
byte[] pbFont, int cbFont, IntPtr pdv, out uint pcFonts);
public Font GetEmbeddedFont(string name, float size)
{
PrivateFontCollection pfc = null;
Font fn = null;
if (null == pfc)
{
Stream stmFont = Assembly.GetExecutingAssembly().GetManifestResourceStream(
MethodBase.GetCurrentMethod().DeclaringType.Namespace + ".Resources." + name);
if (null != stmFont)
{
byte[] rgbyt = new Byte[stmFont.Length];
stmFont.Read(rgbyt, 0, rgbyt.Length);
uint cFonts;
AddFontMemResourceEx(
rgbyt, rgbyt.Length, IntPtr.Zero, out cFonts);
IntPtr pbyt = Marshal.AllocCoTaskMem(rgbyt.Length);
if (null != pbyt)
{
Marshal.Copy(rgbyt, 0, pbyt, rgbyt.Length);
pfc = new PrivateFontCollection();
pfc.AddMemoryFont(pbyt, rgbyt.Length);
Marshal.FreeCoTaskMem(pbyt);
}
}
}
if (null != pfc)
{
if (pfc.Families.Length > 0)
{
fn = new Font(pfc.Families[0], size);
}
}
return fn;
}
Then something like
label1.Font = GetEmbeddedFont("FRE3OF9X.TTF", 30);
If it doesn't work I'll have a play on Vista at home tonight.
Edit: Have tested the code above and it works fine on Vista
Needs the following 'usings'
using System;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
Dave
modified on Monday, March 3, 2008 11:50 AM
|
|
|
|
|
Hello Sir,
I have tried the solution that u gave me but it is not working ....
Before using your solution i was using this one....
class PrivateFonts
{
[DllImport("Gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, int cbFont, int pdv, ref int pcFonts);
public System.Drawing.Text.PrivateFontCollection GetFont(string[] FontResource)
{
//Get the namespace of the application
string NameSpc = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString();
System.IO.Stream FntStrm;
System.Drawing.Text.PrivateFontCollection FntNc = new System.Drawing.Text.PrivateFontCollection();
int i;
for (i = 0; i <= FontResource.GetUpperBound(0); i++)
{
//Get the resource stream area where the font is located
FntStrm = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(NameSpc + "." + FontResource[i]);
//Load the font off the stream into a byte array
byte[] ByteStrm = new byte[(int)FntStrm.Length + 1];
FntStrm.Read(ByteStrm, 0, Convert.ToInt32((int)FntStrm.Length));
//Allocate some memory on the global heap
IntPtr FntPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(typeof(byte)) * ByteStrm.Length);
//Copy the byte array holding the font into the allocated memory.
System.Runtime.InteropServices.Marshal.Copy(ByteStrm, 0, FntPtr, ByteStrm.Length);
//Add the font to the PrivateFontCollection
FntNc.AddMemoryFont(FntPtr, ByteStrm.Length);
Int32 pcFonts;
pcFonts = 1;
AddFontMemResourceEx(FntPtr, ByteStrm.Length, 0, ref pcFonts);
//Free the memory
System.Runtime.InteropServices.Marshal.FreeHGlobal(FntPtr);
}
return FntNc;
}
}
<b>ON BUTTON CLICK</b>
//string[] fontNames = { "FRE3OF9X.TTF" };
//PrivateFonts privateFonts = new PrivateFonts();
//System.Drawing.Text.PrivateFontCollection FntNc = privateFonts.GetFont(fontNames);
//labelBarcode.Font = new Font(FntNc.Families[0], 12);
Can you tell me what modification i have to do to get this work on Vista
because its working nice on XP....
Thanks
|
|
|
|