Update: We are still using XP at work and I got my solution working, but now knowing that Vista and beyond have the isolated session I am going to implement a WCF IPC...
I have a windows service that needs to notify the user of an event of some type occurring. I decided that something similar to email notification messages would make sense. It also makes sense to do such a simple UI using WPF. This would allow me to learn some basics.
I run a thread:
Thread thread = new Thread(new ThreadStart(RunUserNotificationOnIndependantThread));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
Then I set up the object and call the method that calls DoubleAnimation.BeginAnimation
private void RunUserNotificationOnIndependantThread()
{
UserNotificationWithImage test = new UserNotificationWithImage();
test.Title = _title;
test.Url = _url;
test.Message = _message;
test.LoadUserNotification();
}
public void LoadUserNotification()
{
Rect workAreaRectangle = System.Windows.SystemParameters.WorkArea;
Left = workAreaRectangle.Right - Width - BorderThickness.Right;
Top = workAreaRectangle.Bottom - Height - BorderThickness.Bottom;
_fadeInAnimation.Completed += new EventHandler(_fadeInAnimation_Completed);
// Start the fade in animation
BeginAnimation(UserNotificationBase.OpacityProperty, _fadeInAnimation);
}
The debugger reaches BeginAnimation(...) and no window appears. Is this even possible or what am I doing wrong in attempting this???
The UserNotification code is based on a blog by Nicke Andersson: WPF Desktop Alert blog
Thanks for any help!!
On XP a service that interact with the desktop has two serious problems to overcome - what to do when no users are logged in and what to do when several user are logged in (fast user switching and terminal services are the two most common ways to log in more then one user).
On Vista, for security reasons, services run on their own isolated desktop so any UI you show will go on that special desktop that no user can ever access.
You should write a small Gui program that runs on the user's desktop and communicate with the service using some type of IPC (Remoting, Soap, Rest, named pipes, files, whatever you like).
Generally speaking I would not recommend a Windows Service to interact with the user's desktop directly at all. As a simple example, problems arise because the service may start before any user is logged on. My suggestion would be to create a small app that start-up with the user session and communicated to the Windows Service via IPC (Interprocess Communication) such as WCF.
But if you do want to try to get it running, my hint would be switch on "Allow interaction with desktop" for the service and I seem to remember that this switch doesn't work at all under Vista, but someone else should confirm that.
HTH
alex
Related
I have created a WPF application (web scraper), the debug version works as expected on my pc but after copying the files to the clients it shows the User interface and after pressing the button to scrap it doesn't do anything, I am having the same OS as the client (Windows 7 64 bit), I can't guess what the problem is ? can anyone help me ?
Alongside any other diagnostics you are doing to investigate why you can run an app on your machine, but a client cannot run it on his machine is to double check the roles you are both in...
As a developer, you most likely run your development computer with
Full Trust permissions. Therefore, you do not see the same security
exceptions when you debug the application that users may see when they
run it with restricted permissions.
In order to catch these exceptions, you have to debug the application
with the same permissions as the end user. Debugging with restricted
permissions can be enabled on the Security page of the Project
Designer.
When you debug an application with restricted permissions, exceptions
will be raised for any code security demands that have not been
enabled on the Security page. An exception helper will appear,
providing suggestions about how to modify your code to prevent the
exception.
Visual Studio
Here is a snippet to pop up all the various roles...
WindowsIdentity wi = WindowsIdentity.GetAnonymous();
WindowsPrincipal wp = new WindowsPrincipal(wi);
foreach (var e in Enum.GetValues(typeof (WindowsBuiltInRole)))
{
if (wp.IsInRole(e.ToString()))
{
MessageBox.Show(String.Format("{0} is in role {1}", wp.Identity.Name, e.ToString()));
}
else
{
MessageBox.Show(String.Format("{0} is NOT in role {1}", wp.Identity.Name, e.ToString()));
}
}
These things will help you further investigate why the same program behaves differently on two computers driven by two different people.
I dont know if this has to do with how the program is programmed or how it is set up or how it is started.
But I created a program in WPF and I would like to make sure that none of he regular users on the computer shut it down.
The regular users need to be able to interact with it but they should not be able to close it.
The correct approach would be to run the application as a service with permissions set by the administrator to not let the user manipulate the service. Otherwise you will run into trouble with user-initiated shutdown and with preventing the application from being terminated.
If it is the case that the OP wants to prevent visibility of the OS, creating a terminal like experience. The best way to do this is to create a shell replacement.
Then the user wouldn't see the OS as windows directly.
I have registered my Phone 7 app as a Share Picker Extension. It works—my app is in the list of Share options and it gets launched and I can load the chosen image. Okay, great.
But then things go wrong in my code. I would like to be able to debug the issues, but I can't seem to keep the debugger attached.
I cannot debug this in the simulator, since the Pictures app (and thus the Share Picker functionality) is not present in the simulator.
I cannot debug this on the phone because as soon as I pick my app from the Share list, the debugger detaches... right as my app is "launching" again.
Is it possible to attach the debugger to a running WP7 app? Is it possible to keep the debugger attached? Am I doing it wrong? Any suggestions, advice or guesses are welcome because I'm tearing my hair out.
When doing M+V hub integration (sorry, haven't done any pictures hub integration yet) I initially used a crude debug technique (Messagebox.Show, etc. - like Justin mentioned) to verify what was being passed to the NavigationEventArgs of OnNavigatedTo and wrapped the whole method in a try..catch block to learn what was going on. I then refactored the code when I knew what could be expected. (Remember OnNavigatedTo will be called when your app is launched normally too and so e won't be populated in the same way.)
When the app is launched from a/the hub it creates a new instance of the app and there is currently no way to connect to this for debugging while the main page is being navigated to.
Great question. I'm unsure if that's possible. As far as I know, there's no way to attach the debugger to when the WP7 O/S starts an app (which wasn't triggered by the debugger).
Photo Share picker extensibility, music+Video hub extensibility and other O/S extensibility points seem to not play nicely with the VS debugger. Normally I resort to MessageBox.Show to debug any problems with WP7 O/S integration.
1) Connect the Device
2) Turn off Zune
3) Start C:\Program Files\Microsoft SDKs\Windows Phone\v7.1\Tools\WPConnect\x86\WPConnect.exe
To properly debug your application that uses the Media Library, you'll need to use the Windows Phone Connect Tool (WPConnect.exe) as described on MSDN. Jaime has some additional tips on his blog.
Once you are connected, you should be able to debug your application. Fingers crossed anyway. If that doesn't help, I'll dig a bit further.
It's not so much about the WPConnect tool. The nature of your application means that you have to have it closed and the user should pick a photo. Only after that the data is returned to the application.
You should read about the application execution model on Windows Phone 7. Also a good explanation is available here.
Initially, I would say that you should look at tombstoning (a good explanation here) but then again, the image returned will re-start the app and won't allow you to directly attach the debugger.
Yeah, looks like this is impossible...
All the answers above seem to be missing the point: I presume you're able to debug your app in the "standalone" mode (when it's launched normally), but not when it's launched via the Share Picker Extension. Am I write? This is the wall I'm hitting... :-(
I thought the proper way would be to attach to the process once it's launched.
I tried to use Debug > Attach to Process, then select Smart Device as the Transport and Windows Phone Device as the Qualifier... But in return I get the ugly "Unable to connect to 'Windows Phone Device'. Not implemented" message.
Bummer :-(
i have a WPF application that sits on top of all other windows. 99% of the time it works perfectly however if i dial into my computer from another location using remote desktop and then close the connection and go back to the original computer, my application is not visible. checking the running processes i can see that it is still running however its not visible at all. I assume it has something to do with the remoting but i was wondering if there is some code i can run say every 20 seconds that sits on its own thread that checks whether it is visible and if not will execute some code whether by pInvoke or .NET to become visible again. Any ideas?
Make sure to upgrade to .NET 3.5sp1. There were some changes with remoting which lead to WPF applications being sent as bitmaps in remote desktop in all situations.
In earlier versions of the framework, there were problems with WPF applications causing very odd behavior when combined with remote desktop.
Another idea - make sure you're using the latest and greatest versions of your graphics drivers from your graphics card vendor. WPF makes heavy use of DirectX, and this could potentially be a driver bug preventing the context from resetting appropriately.
I would like to configure a WPF application to function in a similar way to SlickRun. I would like to be able to minimize the application to the taskbar, then while in any other program, press a key command (ex: ALT + X) and have my application appear to the user.
Can someone point me in the right direction?
Your best bet is to use RegisterHotKey(). That works by sending the WM_HOTKEY message to the HWND you passed in. Since WPF doesn't expose its windows' message loop to developers, you'll probably need to get your hands dirty with some interop and create a message only window to receive the hot key messages.