|
A timer is for repeatedly (or once) doing something at a specified interval - for use if you want to do something once every xx seconds.
GetTickCount() or QueryPerformanceCounter() is used for finding out how long something takes to complete.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
MSDN says it retrieves the number of milliseconds the system has been running...
how could I it to tell how long it was since a for loop started 'till it ends?
|
|
|
|
|
By calling it before you start, and then again when you finished, and subtracting the starting number from the ending number. This will give you the number of milliseconds the operation took.
int ctr=GetTickCount();
ctr=GetTickCount-ctr;
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
|
eggie5 wrote:
I also checked out the awsome timing article by Daniel S.
Thanks for the link - I'll add it to my toolbox. I've wanted to make something like that, but so far I've not had a compelling reason to do it, so I never did it.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Hi,
I want to know the code to show a windows from when i select a choice from menu.
In VB6 the command is as below, pls tell me equivalent code in C#.thanks
form1.show
|
|
|
|
|
Add the following inside the function that handles the specific menu option you are talking about. In this example, Form1 is the name of your class, f is just an instance of Form1 which you will work with.
Form1 f = new Form1();
f.Show();
-Nick Parker
|
|
|
|
|
I have an application that's running in the background. How do I enable it to catch keys pressed so I can route it to an event?
Nick Seng (the programmer formerly known as Notorious SMC)
God, I pity me! - Phoncible P. Bone
|
|
|
|
|
If it's only for one key or a few keys, you might want to register a hotkey. Otherwise, you might try a system-wide journal hook.
BTW, it might help us if you tell us why you need this capability.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Well, I was thinking of writing a background application, or windows service that can bind any application to a hotkey. That way I can start any application by pressing said hotkey.
Nick Seng (the programmer formerly known as Notorious SMC)
God, I pity me! - Phoncible P. Bone
|
|
|
|
|
Hi.
I need to know when a window is maximized.
Not only a window from my applications, but from all programs on the computer.
Example : Outlook window is maximized -> I need to know it
Example : IE window is maximized -> I need to know it
Example : SomeWindow is maximized -> I need to know it
Thanks
Heelios
|
|
|
|
|
My first thought was that you could implement a global hook, however after reading the Microsoft knowledge article: HOW TO: Set a Windows Hook in Visual C# .NET[^] I found out that global hooks aren't allowed in the .NET Framework So my thought now to you is to do some P/Invoke calling the EnumWindows Function[^] and then calling the IsZoomed Function[^] to determine if each window is maximized. Hope this is a pointer in the right direction for you.
-Nick Parker
|
|
|
|
|
I doubt if there is a way to catch an event, even if you use WndProc for messages.
You'll probably have to do what the previous poster wrote. Run a timer and check every window manually.
|
|
|
|
|
Thats gonna take bunch o processor speed
|
|
|
|
|
Here is what i have... I have a main form with the sortedlist declared on it. then on another for called "Edit" I have set up a struct declaring 2 arrays we will call them array1 and array2. now in the Main form when it is closed there is suppose to be a text file created that gets the info in sorted list. the info in the sorted list is as follows. the key is a student name, and the value is suppose to be thrown to the struct with the two arrays built in. my problem is i don't know how to properly call this function. i get the key in the sorted list to display fine in the text file but for the value instead of printing all the values in my array it prints Lab1.Grades. which is the name of my project(Lab1) and the name of my struct(Grades). here is my code in the exit button
private void btnExit_Click(object sender, System.EventArgs e)
{
FileStream fsFile = new FileStream("Roster.txt", FileMode.Create);
StreamWriter srOutPut = new StreamWriter(fsFile);
Grades studentGrades = new Grades();
foreach (DictionaryEntry Entry in this.slStudents)
srOutPut.WriteLine(Entry.Key.ToString () + "|" + studentGrades.labArray);
srOutPut.Close();
MessageBox.Show ("Thanks for using the Grade Calculator!", "Thank You", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
any help is greatly appreciated thanks Kevin
|
|
|
|
|
Hi!
After months, and months of architecting, programming and debugging we have finished our first
multimedia educationnal software! Great!!!
...*But*, security is lacking..
**************************
Can what follows be done, and how please!??
1- Get a C# Windows Service installed silently (before the normal installation of the software)
that gathers the components' names of the target computer (where the software is installed)
2- Converts those components' names into a string (like, a GUID, sort of...) then sends it
to our web server, encrypted.
3- Our web server then sends back a DLL (or something!.. whatever..!) that is incorporated
with the software that is installed.
4- Every time the application starts, it checks for the Windows Service' string (or unique computer signature) to verify that it matches the DLL that our Web server sent.
DONE!
is this possible, or secure??
How can i do that? I'm fairly proefficient in C# (which is in what our app is written),
and to know how to do this kind of security would be great.
ps.: have any ideas on this method?
thanks!
Antoine Dubuc
Orchus Technologies
This by our hands that dream,
"I shall find a way or make one!" great quote heh?
This by our hands that dream,
"I shall find a way or make one!" great quote heh?
|
|
|
|
|
|
Orlanda Ramos wrote:
Get a C# Windows Service installed silently ... that gathers the components' names of the target computer
Silently install a possibly public web service? No, thanks.
Orlanda Ramos wrote:
...sends back a DLL...
Another silent installation of executable code? No, thanks.
Your application might be safe to sell for you, but the user is at the whim of your company, your code security and every hacker on the 'net, because you introduced a slew of security holes.
If any application would do this kind of dangerous, annoying and extensive license verification, it's probably not worth using.
Ironically, Windows XP introduced seemingly similar techniques. But at the heart, they are different.
|
|
|
|
|
Hi....
If i have lets say two textboxes, wich contains text, for an example a name in textbox1 and someones age in the other textbox. Both these texts are stored with a class with get/set... This is serialized and saved in a file called user.bin
When i,m clicking in the listbox, the text i wrote in the textboxes appears again in the same textboxes like they should, so thats not the issue here, thats working fine...
The thing is i want my listbox to read from the serialized file and show the names i´ve stored in my user.bin file. And this is to happend when i start up the application. The reason is i want to see how many people or names stored in my file...
Bottomline is *How can i make a listbox read from a serialized file???*
|
|
|
|
|
I would make a class for the user information (ie. UserInfo) & also create a collection for the UserInfo class. Mark both classes with the attribute [Serializable()]
when the app loads have it execute something like this
FileStream fs = File.OpenRead(string filename);<br />
BinSerializer s = new BinSerializer();<br />
UserInfoCollection c = (UserInfoCollection)s.deserialize(fs);<br />
foreach(UserInfo i in c)<br />
{<br />
listbox.items.add(i.name);<br />
}
|
|
|
|
|
Anyone know of the cleanest way to have windows restart via c#?
I thought it would be in the SYSTEM namespace, but can't find anything there, lot's of docs on how to detect if it's happening but can't seem to find anything on how to cause it to happen.
------------
|
|
|
|
|
Use EcitWindows() API
Mazy
No sig. available now.
|
|
|
|
|
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}
[DllImport("kernel32.dll", ExactSpelling=true) ]
internal static extern IntPtr GetCurrentProcess();
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok );
[DllImport("advapi32.dll", SetLastError=true) ]
internal static extern bool LookupPrivilegeValue( string host, string name, ref long pluid );
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen );
[DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool ExitWindowsEx( int flg, int rea );
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
internal const int EWX_LOGOFF = 0x00000000;
internal const int EWX_SHUTDOWN = 0x00000001;
internal const int EWX_REBOOT = 0x00000002;
internal const int EWX_FORCE = 0x00000004;
internal const int EWX_POWEROFF = 0x00000008;
internal const int EWX_FORCEIFHUNG = 0x00000010;
private void DoExitWin( int flg )
{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok );
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );
ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero );
ok = ExitWindowsEx( flg, 0 );
}
// usage:
DoExitWin( EWX_POWEROFF );
Cheers
ES
|
|
|
|
|
Hi,
I would like to know of an advanced log library/component for .NET, something that supports logging to Event Log, File, E-Mail, maybe some realtime console.
I'm looking for something robust for .NET. If it's free even better .
Any comments and suggestions are appreciated.
(I've seen log4net on sourceforge already)
Thanks,
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
How do I tab to the next edit box using the Enter key??
Also how do I do a message box in c#??
Thanks
|
|
|
|