How to programmatically close a MessageDialog in Win8 app using WinJS? - windows-8

Here is a similar question to mine regarding how to programmatically close a MessageDialog in a Win8 app, but the author of the question is using C#. I'm curious about how to solve the issue with WinJS. Is there any way to cancel a MessageDialog programmatically with WinJS without have access to the CommanUI objects within the dialog itself? I cannot simply invoke the handler associated with an appended CommandUI button since, in some cases, I wouldn't know which button index has that functionality.
Any tips?
Thanks!

MessageDialog.showAsync returns an IAsyncOperation<IUICommand> object and inherits from IAsyncInfo. The IAsyncInfo interface includes a cancel method which generically cancels asynchronous operations. In the case of the message dialog, calling cancel on the async operation will dismiss the dialog if it is still present.
var asyncOperation = messageDialog.showAsync();
asyncOperation.cancel();
More info on the WinRT asynchronous programming pattern can be found on MSDN.

Related

Windows Automaton - InvokePattern blocking execution until everything has completed

I have experienced this behavior in my automation application: when I "click" a button by calling the InvokePattern.Invoke() method everything stops until the handler of the click event inside the automated application finishes.
While this can make some thing simple (for example I don't have to write tons of code to wait for a dialog with progress bar to disappear, because I simply get the control back when everything is done), but I can't do anything else. It even blocks the access to the Automation API in another thread where it continues after the click handler is done.
This causes problems when click handler in the automated application opens a modal dialog, then I can't do anything, the access to the application through automation API is blocked until the dialog is manually closed.
Has anybody solved this somehow and can help me?
Thanks,
Karel
PS: Reference source is saying this:
Request that the control initiate its action.
/// Should return immediately without blocking.
/// There is no way to determine what happened, when it happend, or whether
/// anything happened at all
public void Invoke() { ... }
Edit: It works perfectly when automating Windows notepad application which is not a .NET application. And it does not work for a Notepad clone (C# WinForms aplication).

VB.NET access winforms non-public member

In my application that uses a multi-document interface model I have one of the windows that is constantly refreshing itself in an asynchronously. And when the UI launches another window (wizard for instance), newly created window can in some cases loose focus(wasn't able to reproduce this behavior, but is was reported by many).
I think this can be related to the fact that when async function finishes in main window it actually grabs the focus back(but apparently it only happens when wizard window doing some computation).
I was planning to cancel the timer updates in a main window when it is not active. But hit a problem of inability to access "My.Active" property.
I can see it in a debug but cannot access it from the code:
This is a partial screenshot of "My" component:
I must be missing something simple, but wasn't able to figure this out for a couple hours now.
I ended up using Reflection to get the property as it was suggested in comments to my question. It's not pretty but it works for my current scenario.
Here is the solution:
Dim prop As System.Reflection.PropertyInfo = Me.GetType().GetProperty("Active",
System.Reflection.BindingFlags.NonPublic Or
System.Reflection.BindingFlags.Instance)
Dim value As Boolean = prop.GetValue(Me)

Windows 8 MessageDialog, dynamically update content

There is one MessageDialog with text, that must be updated on timer (DispatcherTimer). Debugger shows, that on timer tick Content property is assigned, but visually there are no changes. Is there any tricky way to display new title?
MessageDialog blocks the UI thread until it's closed. So, you cannot change anything on the UI until it's closed. The only you can update it you need to call ShowAsync() method periodically in the tick event of the DispatchTimer. However, before closing the old message dialog, it won't work. Best way to achieve this, uou should implement your own message dialog as a user control.

Dismiss dialog coming from outside my application

In my application I perform an operation which causes an internal Android app to pop up AlertDialog over my application.
Is it possible to somehow dismiss this Dialog programmatically? Unfortunately I can't find the access to this Dialog object.
I've tried overriding onCreateDialog() method in my Activity, but as my Activity is not an originator of Dialog window, this method is not being called when it pops up.
I was also thinking about getting list of all objects that appear on the screen, but I assume there's no such method?
To my understanding you are doing something that is requiring some user interaction, like bluetooth pairing, in which case this Dialog is brought up by the system... possibly (System Dialog) which is not controlled by you. To solve this...
One thing you can try is:
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
public static final String ACTION_CLOSE_SYSTEM_DIALOGS
Added in API level 1 Broadcast Action: This is broadcast when a user
action should request a temporary system dialog to dismiss. Some
examples of temporary system dialogs are the notification window-shade
and the recent tasks dialog.
Constant Value: "android.intent.action.CLOSE_SYSTEM_DIALOGS"

accessing dynamically created form elements from a thread in vb.net

I am new to VB and .Net and I have a task that I am unable to proceed.
I start a thread when screen1 Loads. User then goes to screen2.
On screen2 the thread is still running behind. when the user performs an action(say click) on screen2, it will trigger the thread to access elements on screen2
The elements in screen 2 are dynamically created and not designed in IDE.
So in essence a thread that is created on one form needs to access dynamically created form elements on another form.
If my question is too simple, please forgive me. If it is not clear please let me know and I will rephrase it.
Note: The element that I am talking about is basically a picture box inside a flow layout panel.
Thanks in advance
All help is eagerly(biting nails now) awaited and greatly appreciated.
EDIT
Lets say a thread called ctThread was started in dashboard screen
ctThread.start()
This thread is running endlessly, waiting for a trigger event.
Meanwhile User has gone to a screen called QuizScreen and on this screen(form) I have to update some dynamically created elements whose names I know.
So when the time is right for ctThread which is waiting (Listener Thread) it will call the sub below.
Sub
public sub changeComputerStatus(ByVal node)
Dim flowpanel As FlowLayoutPanel = CType(QuizScreen.FlowLayoutPanel1.Controls("flow_" + node), FlowLayoutPanel)
Dim pictControl As PictureBox = CType(flowpanel.Controls("pict_" + node), PictureBox)
pictControl.Image = System.Drawing.Image.FromFile(Application.StartupPath & "\images\application-on.png")
end sub
here node keeps changing. This is how I differentiate each control I create.
Note : This thread was started in a screen called dashboardscreen and the user is now on a different screen QuizScreen.
The first line of the sub I gave above runs and returns nothing to the flowpanel. Hence when It goes to the next line, it is not able to use the nothing as reference. And hence the above mentioned error.
Two things.
The most important thing you must know is that you cannot directly access a control's properties from a background thread. Controls may only be manipulated from the foreground UI thread. In order to access controls from a background thread, you need to use some form of asynchronous programming, e.g. creating delegates a la .NET 1.x - 3.5 or using the new Task<T> and async and await keywords.
Did you actually add the dynamically created controls to the form's control collection? Mind you, you'll still need to access the controls via delegates or some other asynchronous method as explained in 1 above.
UPDATE:
To answer the question in the OP's comment below: you can also Invoke a method on a UI object. Basically, you're telling .NET to run the invoked method and it runs on the UI object's creating thread (in this case, the UI thread), which is what you want. This will allow you (depending on the method or property invoked) to "update" the control "from the background"—again, this is all sleight of hand; when invoking a method on a UI object, the invkoked method runs on the UI thread possibly using data passed into said method from the background task.
Also, check out the MSDN documentation on the BacgkroundWorker (this was introduced in .NET 2.0 and is superseded by the async and await keywords along with Task<T> in .NET 4.5). There is lots of documentation available that explains exactly how to do what you're asking. It's not hard to find by performing a quick search on MSDN or Bing (or your preferred search engine).