This question already has answers here:
NotifyIcon.ShowBalloonTip not keeps timeout
(4 answers)
Closed 5 years ago.
I have an application, that uses some tooltips. The "Timeout" is driving me crazy by now:
No matter, what timeout value I provide in the following snippet:
(Config is just a static class holding references during runtime)
public static void notify()
{
Config.NotifyIcon.Visible = true;
Config.NotifyIcon.BalloonTipText = "BalloonTipText";
Config.NotifyIcon.BalloonTipTitle = "BalloonTipTitle";
Config.NotifyIcon.BalloonTipIcon = ToolTipIcon.Info;
Config.NotifyIcon.ShowBalloonTip(1 * 60 * 1000);
}
The behaviour is "unexpected":
If I don't do anything, after the method is called - the BalloonTip stays unlimited it seems. (At least it was > 45 minutes by now)
But if the BalloonTip appears and I move the cursor - it vanishes after 2-3 seconds...
Test it on Windows 7 and Windows 10, both time the same problem.
Any Idea?
Microsoft says in the documentation for the ShowBalloonTip method that
This parameter is deprecated as of Windows Vista. Notification display times
are now based on system accessibility settings.
When you are not using the computer (moving the mouse or typing), Microsoft says:
In addition, if the user does not appear to be using the computer (no
keyboard or mouse events are occurring) then the system does not count this
time towards the timeout.
Related
This question already has answers here:
How to Call Windows API [duplicate]
(2 answers)
how to set timer resolution from C# to 1 ms?
(2 answers)
Closed 2 years ago.
I have a WPF application that controls a robot arm. It's also a human-in-the-loop system. So I would like it to be as close to real time as possible. I am using a DispatcherTimer to generate a "tick" regularly to update the robot arm. Sort of like a poor mans Gameloop:
public partial class MainWindow : Window
{
DispatcherTimer Timer;
public MainWindow()
{
InitializeComponent();
Timer = new DispatcherTimer(DispatcherPriority.Send);
Timer.Interval = TimeSpan.FromMilliseconds(10);
Timer.Tick += new EventHandler(OnTick);
}
private void OnTick(object sender, EventArgs e)
{
//1.Read input devices
//2.Do calculations
//3.Move robot arm
}
}
To be as near to real time as possible, this tick has to be generated as fast as possible, but because of limitations in Windows, the line...
Timer.Interval = TimeSpan.FromMilliseconds(10);
...has no real effect for values under ~15. It is limited by the fact that Windows schedules the "sleeps" and "wakes" of threads in 15.6ms intervals as explained nicely by Bruce Dawson here.
But, as is also explained in this article, this default scheduling interval can be changed by calling timeBeginPeriod in timeapi.h
Can someone show or point me to an example how to call WinAPI functions, like timeBeginPeriod(10); from a WPF application?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Im creating a system based on fingerprint recognition and for this reason I am doing a windows service , using DigitalPersona, which is a fingerprint reader.
This reader has many methods like onFingerGone, OnFingerTouch and others. This methods are events that are fired when the fingerprint reader is touched.
Everythig goes well until that part. But when there is no activity.... (i mean that when the fingerprint reader is not touched) throws an error in the console.
"The proccess exited with code 0"
Please help.
Some details:
- using Visual Studio 2010 .Net 4
Error code 0 means that were no errors.
Using events (OnFingerGone, OnFingerTouch) means your application to wait for them. "The proccess exited with code 0" usually means that main thread (?) of your console application is done or that your WPF, WinForms, etc. application called something like this.Application.Close().
For example:
class Pseudocode {
event EventHandler myEvent;
int main(){
myEvent += onMyEvent;
//do work 1
return 0;
}
void onMyEvent(Object sender, EventArgs e){
//do work 2
}
//other methods and work
}
If amount of work in main() is small, application will be closed immediately.
In console application you can prevent this simply adding Console.ReadLine(); (before return 0; according to example), so your application will be waiting for "Enter" key.
In windowed application you need to look for manual exit calls or something like this because they are not known as "self-closable".
This question already has answers here:
What is the correct way to create a single-instance WPF application?
(39 answers)
Closed 9 years ago.
The app I am creating includes a notify icon and it is in a way that stays active in the background (well, sort of). The problem is that when the user clicks on the icon of my app, the app will launch again, and so I have two notification icons and two activities in the background and two of everything. And if the user clicks the icon again, there will be three of all those things and...... so somehow I should stop this. I have kind of an idea of setting a flag and setting its value to registry, and when my app wants to start, in the form load event, by reading the value, terminates the app. But I want a more... professional way to deal with it. For example not being started at all.
this is from this answer which is a duplicate of this one. You check in your app's entry constructor for whether or not the app is already running.
static void Main()
{
Process currentProcess = Process.GetCurrentProcess();
var runningProcess = (from process in Process.GetProcesses()
where
process.Id != currentProcess.Id &&
process.ProcessName.Equals(
currentProcess.ProcessName,
StringComparison.Ordinal)
select process).FirstOrDefault();
if (runningProcess != null)
{
ShowWindow(runningProcess.MainWindowHandle, SW_SHOWMAXIMIZED);
return;
}
}
create some form of Global Mutex/Event handle that your app creates and then in your open routine check for it being present, if it is, exit the startup routing.
I have some basic code here in this answer I gave (for a different issue), but it demonstrates what you are trying to do.
UnauthorizedAccessException on Openexisting global mutex
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Best way of detecting if Windows has Windows Updates ready to download/install?
I am using C# .net 3.5.
How can I know if there are updates ready to be installed in Windows Update?
On windows 8, when Windows Update is waiting to install updates, the sleep option is disabled.
Instead of the regular 3 options: 1. Sleep 2. Restart 3. Shutdown, there are only 2 options: 1. Restart and update 2. Shutdown and update. I need to identify this state and notify the user that the machine cannot move to sleep mode becuase updates are waiting to be installed.
Can I do it using WUAPILib?
Thanks
You can use WUApiLib (Com lib) for this:
var updateSession = new UpdateSession();
var updateSearcher = updateSession.CreateUpdateSearcher();
updateSearcher.Online = false; //set to true if you want to search online
try
{
var searchResult = updateSearcher.Search("IsInstalled=0 And IsHidden=0");
if (searchResult.Updates.Count > 0)
{
MessageBox.Show("There are updates available for installation");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Error");
}
Click here if you want to know more.
Background
My son likes to use his laptop when he's not supposed to and I just thought it would be handy if I could write an application that would email me whenever he opened / closed his laptop.
(I'd even settle for something that notified me when there was network traffic on the machine)
Question
How do you programmatically detect when an OS is waking up or going to sleep? I found this link from this related post. But that covers OS X. I'm looking for the same thing for Windows 7.
(I'd like to do this in Java, if possible, but I'd settle for C#/C++)
Easiest way is not to write any code at all, even though this is stack overflow. Click Start, type Schedule and choose Scheduled Tasks. Set one up (click Create Task) and set a Trigger when the machine is unlocked. For the Action, have it send you an email.
Repeat for startup and when a user logs in, if you want. Done.
You're going to want to create a window and watch for the WM_POWERBROADCAST message (http://msdn.microsoft.com/en-us/library/aa373248%28v=vs.85%29.aspx) and check the wParam for your desired action. For example, your window should receive a WM_POWERBROADCAST with PBT_APMSUSPEND as the wParam when the system is about to enter a suspended state (i.e. closing a laptop). Resuming seems to have a few different wParam values: PBT_APMRESUMESUSPEND, PBT_APMRESUMECRITICAL and PBT_APMRESUMEAUTOMATIC
I search for a long time and found that this was the best way, the 'Sleep'-event was never working before:
private ManagementEventWatcher managementEventWatcher;
private readonly Dictionary<string, string> powerValues = new Dictionary<string, string>
{
{"4", "Entering Suspend"},
{"7", "Resume from Suspend"},
{"10", "Power Status Change"},
{"11", "OEM Event"},
{"18", "Resume Automatic"}
};
public void InitPowerEvents()
{
var q = new WqlEventQuery();
var scope = new ManagementScope("root\\CIMV2");
q.EventClassName = "Win32_PowerManagementEvent";
managementEventWatcher = new ManagementEventWatcher(scope, q);
managementEventWatcher.EventArrived += PowerEventArrive;
managementEventWatcher.Start();
}
private void PowerEventArrive(object sender, EventArrivedEventArgs e)
{
foreach (PropertyData pd in e.NewEvent.Properties)
{
if (pd == null || pd.Value == null) continue;
var name = powerValues.ContainsKey(pd.Value.ToString())
? powerValues[pd.Value.ToString()]
: pd.Value.ToString();
Console.WriteLine("PowerEvent:"+name);
}
}
public void Stop()
{
managementEventWatcher.Stop();
}
A very simple, perhaps crude, but effective way may be to have a program with a timer firing every minute. If the timer fires and it's been, say, 5 minutes of real time since its last execution then you can likely assume that the computer was sleeping since it's unlikely that your thread was unable to be scheduled for so long.
The other reason for the difference may be a clock adjustment, like DST or a manual change, but that kind of "noise" should be very low, in your scenario.
You could write a simple app and register it as a Windows service, to be started automatically at system startup. This app could then do whatever you want when it starts. And if it's a proper Windows app, it can register to get notification about impending system shutdown too (I don't remember the details but I implemented this in a C++ MFC app many years ago).
If you prefer Java, you could register your app as a service via a suitable service wrapper like Tanuki (it seems they have a free Community License option). Although this might be overkill. And it may be possible to get notification about the JVM shutting down when the system is closing (but I have no concrete experience with this).
http://www.pinvoke.net/default.aspx/powrprof.CallNtPowerInformation - Check out the link. It has almost all win32api for all windows function. You can call power management feature directly in your windows 7 laptop. For that create a Windows Service , that will use these specific api to notify the machine state.