when does the activated event fire in windows phone 8.1 WINRT apps - windows-8

I have overridden the OnActivated event in the app.xaml, but the handler is never executed
protected override void OnActivated (IActivatedEventArgs args)
{
//Test Code
}

I think you mix Resuming and Activation. In WP8.1 RT it works little different that in WP8.0. Please take a look at App Lifecycle. There is a list in which cases your app is being activated. For example you will have OnActivated launched after FileOpenPicker but you won't get it fired after Suspension (then the Resuming event is fired).
You won't be able to test your OnActivated by using lifecycle event dropdown. To test it you will have to get it invoked (take a look at these lifecycle events at msdn), also open project properties, go to Debug and mark a tick Do not launch, but debug my code when it starts.
Please also remeber that your app can be terminated by the OS (for example due to lack of resources) while it's deactivated/suspended.

Related

Access the EPartService after an RCP application has initialized

After my application initialized, I'm trying to automatically create a part within a part stack. I need the EPartService for this but I can't think of any way to properly get a hold of this service.
I've tried using the LifeCycle management to get the current IEclipseContext. However, whenever I try to access the service using the context, it's not found.
Any idea how I can do this?
You should be able to inject the EPartService in any of the defined methods in your life cycle class. However you won't be able to show a part until the application startup is complete. So use the App Startup Complete event, by adding a method like this to the life cycle class:
#Optional
#Inject
public void appStartupComplete(#UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event,
EPartService partService)
{
....
}

Can I detect if my Windows 8 application is running?

I have a background task that I want to behave differently if the application is running. How can I detect if my Windows 8 store application is running?
Assuming that you want your app to behave differently when it is in focus, here is how I handled it in my code -
In your class constructor -
CoreWindow.GetForCurrentThread().Activated += CoreWindowOnActivated;
Then, add the implementation -
private void CoreWindowOnActivated(CoreWindow sender, WindowActivatedEventArgs args)
{
if (args.WindowActivationState == CoreWindowActivationState.CodeActivated)
{
//add your app specific behavior here
}
}
You will also need to detach the event when appropriate.
If I was doing this in WinForms I would use a Mutex,
foreground app can lock it
When the foreground app exits for any reason, then windows will unlock the Mutex
The background app can check if the Mutex is locked.
Sorry I don’t know I this work for a windows store app.

AIR application Mouse.hide() not working

I created a fullscreen app with the following to hide the mouse...
// need this hack to hide the mouse for AIR for some reason...for OSX
// http://blog.formatlos.de/2008/11/16/air-hiding-the-mouse/
stage.nativeWindow.activate();
stage.nativeWindow.orderToBack();
stage.nativeWindow.orderToFront();
Mouse.hide();
This works on my machine at home running OSX Lion...but when this is installed on the client's machine (also running OSX...I need to find out the version), the mouse does not hide?
When I take out the 3 line hack before the Mouse.hide(), the mouse does not hide on my machine. Will test this out on the client's machine too.
Anyone experience this before?
Are you including flash.ui.Mouse in your code?
import flash.ui.Mouse;
Take a look in this site: http://samhassan.co.uk/2008/10/08/air-10-mousehide-work-around/
You could try to hide mouse cursor when the first enterFrame event is fired. Some elements are not fully available till the first frame is build:
// i.e. on main app initilize event handler
addEventListener(Event.ENTER_FRAME, onEnterFrame);
private function onEnterFrame(event:Event):void {
Mouse.hide();
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
This way, you have not to rely on hacks or workarounds.

Calling App Expose In Lion

Is there any way to call App Expose in Lion programmatically, for example on an event tap, etc?
If you don't mind using a TOTALLY UNDOCUMENTED API, which might change at any point without notice:
void CoreDockSendNotification(CFStringRef, void *);
(...)
CoreDockSendNotification(#"com.apple.expose.front.awake", NULL);
Other known arguments are #"com.apple.expose.awake" and #"com.apple.dashboard.awake", which activate Mission Control and Dashboard, respectively. #"com.apple.showdesktop.awake" used to activate Show Desktop, but no longer works on current versions of macOS.
Note that most applications should not use these calls -- these actions are intended to be invoked directly by the user.
Expose does not exist in Lion, it has been merged with Spaces into the Mission Control application.
You can launch Mission Control:
[[NSWorkspace sharedWorkspace] launchApplication:#"Mission Control"];

How best execute query in background to not freeze application (.NET)

My WinForm apps needs to execute complex query with significant execution time, I have no influence (about 10mins)
When query is executing user sees 'application not responding' in task manager, which is really confusing to user, also not very professional...
I believe that query shall be executed in different thread or so. Have tried some approaches but have difficulties to make it really working (execute query, force main application wait result, return back to main app, possibility to cancel execution etc)
I wonder if you have own / good working solution for that. Code samples would be also very welcome :)
Also I believe there might exist some ready to use utilities / frameworks allowing simple execution of that.
The simplest approach here would be to do that work from a BackgroundWorker. MSDN has examples for this. This then executes on a worker thread, with events for completion/error/etc. It can also support cancel, but your operation needs to be coded to be interruptable.
Another approach is the Task API in 4.0; but if you use this you'll need to get back to the UI thread (afterwards) yourself. With BackgroundWorker this is automatic (the events are raised on the UI thread).
If ExecuteQuery if the method you want to execute, you can do:
void SomeMethod() {
var thread = new Thread(ExecuteQuery);
thread.Start();
}
void ExecuteQuery() {
//Build your query here and execute it.
}
If ExecuteQuery receives some parameters, like:
void ExecuteQuery(string query) {
//...
}
You can do:
var threadStarter = () => { ExecuteQuery("SELECT * FROM [Table]"); };
var thread = new Thread(ThreadStarter);
thread.Start();
If you want to stop the execution of the background thread, avoid calling thread.Abort() method. That will kill the thread, and you do not want this, because some incosistency could appear in your database.
Instead, you can have a bool variable visible from ExecuteQuery and from outside you can set it to True when you want to stop it. Then all you have to do is check in some parts of the code inside ExecuteQuery if that variable is still True. Otherwise, do some rollback to maintain the database stable.
Be sure you set that bool variable volatile
Edit:
If you want the UI to wait from the background thread, I usually do:
Start the background thread
Start some progress bar in the UI
Disable some controls (like buttons, etc) to avoid the user to click them while the background thread is working (eg: If you're executing the thread when a user clicks a button, then you should disable that button, otherwise multiple queries will be ocurring at the same time).
After finished the thread, you can stop progress bar and enable controls again.
How to know when the thread finished? You can use Events for that. Just create an event and fire it when it finishes, and do whatever you want inside the event handler...
Be sure you're accessing correctly to UI controls from the background thread, otherwise it will give you an error.
If you are new to threads and task is simple (as it seems), you should try to use standard background worker component.