|
Hi all,
I am writing a program on a notebook which it can alert an event preset at certain time, e.g. I can register an event at 3:00 p.m. to the application, so it can alert me at 3:00p.m for the event. And the current method I think of is to write a loop to check whether it is the time for the events. But it will certainly consume computing power for the notebook when it is in battery mode. So is there any feature in the shell that I could register an event and get a signal from it when the time matches ? or any other good method for it ?
Thanks
|
|
|
|
|
Simply use a timer for this. Calculate the number of milliseconds that have to elapse before the event should occur and use it as timer interval.
www.troschuetz.de
|
|
|
|
|
Thanks for your reply.
But there will be many events(unknown number), so I can't keep
a timer for each events(too expensive for the resource). What should I do ?
|
|
|
|
|
You could order your events in some way and use a timer for the closest event. If this event occurs restart the timer for the next event.
www.troschuetz.de
|
|
|
|
|
See System.Timers.Timer
Works like this
public class Timer2<br />
{<br />
<br />
public static void Main()<br />
{<br />
System.Timers.Timer aTimer = new System.Timers.Timer(10000);<br />
aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);<br />
aTimer.AutoReset = false;<br />
aTimer.Enabled = true;<br />
<br />
Console.WriteLine("Press \'q\' to quit the sample.");<br />
while(Console.Read()!='q');<br />
}<br />
<br />
private static void OnTimedEvent(object source, ElapsedEventArgs e) <br />
{<br />
Console.WriteLine("Hello World!");<br />
}<br />
}
Salil Khedkar [^]
|
|
|
|
|
A Timer could be used, but not to fire off the event you want at a specified time. Don't count down to the target time. Instead, setup the timer to fire off every, say, minute. In the timer Tick event handler, get the current system time, then compare that to your schedule of procedures that you need to execute. If the current system time (don't compare down to the second!) matches the schedule time, kick off the code you need to.
Now, you don't have to have a Timer for every event you need, and you don't have to worry about what your going to do if the system crashes and you have to restart your app, recalcualte all the timer intervals, reset the timers, and hookup the tick events again.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi! Nair,
I can not find the answer by myself in MSDN.
Can you tell me where I can get the answer to this question? or you can tell me the answer directely.
Thank!
Best regards!
momer
|
|
|
|
|
Hi ,
As anyone encountered an error message stating that the form that was specified as the MDI Parent is not an MDIContainer. I can understand that this would arise when the form has not had the IsMDiContainer property to true however i have set this property and the application was running fine until yesterday evening any ideas. i am about to unistall framework and VS2003 and reload.
Can anyone help?
Cheers
dazzler
|
|
|
|
|
That would most likely be a complete was of time. For one, VS.NET is merely a client for the .NET Framework, which is a separate component. It implements and uses code to facilitate designers and invokes the compilers to compile managed code, but nothing more (regarding the .NET Framework).
The .NET Framework - especially Windows Forms - P/Invokes and uses COM interop with native Windows APIs.
More than likely, something changed on your system. Did you install any new patches or service packs? Did you change any code - no matter how "unrelated" you think it is? Have you made sure that you're disposing any modal dialogs or other resources (like any Graphics or Bitmap instances you create)? In most cases the fault is with the code. Just re-installing the .NET Framework will almost never solve the problems. You need to first look at your code.
So be more specific about your problems and what exceptions - if any - you're betting. Give us stack traces and other details regarding your problem, but don't just go reinstalling everything. Not only is that a bad way to resolve issues (not knowing what the problem is - no matter if the fix works or not - will most likely lead to the problem happening again), but it most likely won't resolve your issue.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi guys
Does anyone know of any articles/tutorials on ANY web site that can paste files that have been copied to clipboard by Windows Explorer? Specifically I need to know how to cast the "Preferred DropEffect" clipboard format to DragDropEffect enumeration in C#. I can do this in C++, but how do I cast them in C#? Also, do I need to cast from an STGMEDIUM structure, then get the hGlobal to the DropEffect DWORD, or does Clipboard automatically do this in .net for casting from DataObjects?
Any pointers would be greatly appreciated
Thanks guys
|
|
|
|
|
This has been covered before in this forum. In the future, try searching first. You can search these forums by clicking the "Search comments" link above.
You don't need to worry about the STGMEDIUM . Basic drag and drop support is supported by .NET, and even in the COM world you don't simply cast an IDataObject (which, BTW, is a completely different interface from .NET's IDataObject ).
In both implementations, however, you do the same: you request a specific clipboard format that you support (optionally supporting multiple clipboard formats that you reference in order of preference till the data is dropped/pasted).
File names - which use the TYMED_FILE clipboard format - are easy to retrieve. Just look at the following example (assume the handler is hooked up to a DragDrop event for some control):
private void myControl_DragDrop(object sender, DragEventArgs e)
{
if ((e.AllowedEffect & DragDropEffects.Copy) != 0 &&
e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string filename in filenames)
listView1.Items.Add(filename);
}
} You should read the DataFormats class documentation and the DragDrop event documentation for more information.
Only in some cases - like handling data from a stream or structure storage document do you really need to interop with the native COM drag and drop/clipboard APIs, and I've carried on long discussions about this that you can search for and read if you're interested.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
class ball
{
int x;
ball()
{ x=Random().Next(10);
}
}
I then create 10 ball, the problem is all balls have the same X. How do I solve this? Thanks
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
try creating a new random object into the class and giveing it a new seed (that could be time dependent)
<br />
class ball<br />
{<br />
int x;<br />
Random r;<br />
ball(seed)<br />
{ <br />
r=new Random(seed);<br />
x=r.Next(10);<br />
}<br />
<br />
}<br />
<\code> <br />
<br />
I hope you understand...<br />
By the way... visit <a href="http://nehe.gamedev.net">http:
|
|
|
|
|
Try to re-use the same Random:
class ball
{
int x;
Random random = new Random();
ball()
{
x=random.Next(10);
}
}
|
|
|
|
|
Corinna John wrote:
class ball
{
int x;
Random random = new Random();
ball()
{
x=random.Next(10);
}
}
The above is still creating a new Random for each new instance of ball. To reuse one Random it would need to be static, possibly:
class ball
{
int x;
private static Random random = new Random();
ball()
{
x=random.Next(10);
}
}
|
|
|
|
|
Hi all,
I have a windows form application which is a MDI. It has a basic editing toolbar (add,edit,delete buttons). I want to enable the toolbar buttons if a MDI child is active. Disable them when no MDI child is active. How can I do this?
|
|
|
|
|
This is a matter of logic. See here i have a tool bar with few toolbar buttons.I will nable or disable toolbar buttons based on users selection.
Eg:
private void PBToolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
try
{
switch(PBToolBar.Buttons.IndexOf(e.Button))
{
case 0:
{
formA PBAUS = new formA();
PBAUS.Show();
}break;
case 1:
{
toolBarButton10.Enabled=false;
LoadPlan();
}break;
case 2:
{
MessageBox.Show(e.Button.ToolTipText.ToString());
}break;
case 3:
{
save();
toolBarButton10.Enabled=true;
menuItem11.Enabled=true;
}break;
continue.......................
Here what i am doing is , i am getting the index of toolbar button that user clicked.And based on this values i will enable or disable toolbar buttons.
See the logic above and try to figurout your self to achive your goals.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
[C#]
[StructLayout(LayoutKind.Explicit)]
public class SYSTEM_INFO
{
[FieldOffset(0)] public ulong OemId;
[FieldOffset(4)] public ulong PageSize;
[FieldOffset(16)] public ulong ActiveProcessorMask;
[FieldOffset(20)] public ulong NumberOfProcessors;
[FieldOffset(24)] public ulong ProcessorType;
}
In C#,ulong type data has 8 bytes capacity.
How many bytes between field OemId and field PageSize?
Thanks!
momer
|
|
|
|
|
|
Hi! Nair,
I can not find the answer by myself in MSDN.
Can you tell me where I can get the answer to this question? or you can tell me the answer directely.
Thank!
Best regards!
momer
|
|
|
|
|
The constructor documentation[^] for the FieldOffsetAttribute clearly states that the offset is in bytes.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi! Stewart,
1,I want to invoke the DeviceIoControl() API in C#,then how to define IOCTL_SCSI_PASS_THROUGH ?
//vc++ code :
DeviceIoControl( hFile, IOCTL_SCSI_PASS_THROUGH, &SPTWB, length,&SPTWB, length, &dwBytesReturned, FALSE );
Should I copy all the definition of those terms which construct the definition of IOCTL_SCSI_PASS_THROUGH form some headfiles to my c# porject? or there is an other way to do the same work?
2,ZeroMemory( &SPTWB, sizeof( SCSI_PASS_THROUGH_WITH_BUFFERS ) );
I can not find the dll file which
contain this funtion.
How to this in c#? Or there is another function to do the same work in C#?
Best Regards!
momer
|
|
|
|
|
You should start by reading about the classes you're plan on using, like the StructLayoutAttribute and FieldOffsetAttribute (which is typically only useful when you need to declare a struct where the native definition uses a union ). You should also read Marshaling Data with Platform Invoke[^] to better understand how data is marshaled as well as type mappings (like that an unmanaged long is a managed int ; both are 32-bits - this is a common mistake that shouldn't be made).
I would define the IOCTL_SCSI_PASS_THROUGH like so:
internal const int IOCTL_SCSI_PASS_THROUGH = 0x4d004; It's a constant - not a struct.
If you want to find P/Invoke signatures for many commonly used Win32 APIs, I suggest you take a look at http://pinvoke.net[^]. It even has the signature for DeviceIoControl[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi!Stewart,
Thank you very much.
Cheers!
momer
|
|
|
|
|
Hi!Stewart,
Thank you very much.
Cheers!
momer
|
|
|
|