Windows phone map broken multitasking - multithreading

When user opens map, my app starts loading much data from DB to show on map (when it's loaded).
But what i see is that map control stops loading/showing tiles when BG thread is loaded with hard work.
AFAIK WP7 doesn't support thread priorities.
This is really weird. Simple while(true) on BG thread stops map from showing new geodata on zoom/pan.
Maybe any ideas ?
Repro project: https://www.dropbox.com/s/21fmgepcdzf3u1n/Map_bug_Repro.zip
If you start it - map won't load. If you edit MainPage.xaml.cs and comment thread creation - it will work fine.
Thanks!

Related

Cannot get QWindow::fromWinId to work properly

My Qt 5.9 program (on X11 Linux) launches other applications, using QProcess.
I would like to have control over windows these applications spawn, so I obtain their winId value and use QWindow::fromWinId to get a QWindow instance.
The problem is these instances are invalid and do not represent the window they are supposed to.
If I check the winId values using xwininfo, the correct information is returned, so I know they are good.
What am I doing wrong?
Edit: An example won't help much, but here goes:
QProcess *process=new QProcess(this);
...
process.open()
... // wait until window appears
WId winId=PidToWid(process->processId()); // this function returns the Window ID in decimal format. I test this with xwininfo, it's always correct
...
QWindow *appWindow=QWindow::fromWinId(winId);
... And that's basically it. appWindow is a valid QWindow instance, but it does not relate to the actual window in any way. For example, if I close() it, it returns true but the window does not close.
Even if I provide a wrong WId on purpose, the end result is the same.
This is not proper solution with explanation why it should work, however it may be helpful for somebody...
I had the same issue with my application when I switched from Qt4 QX11EmebeddedContainer to Qt5 implementation using QWindow. What I did to resolve / fix this issue was following:
Client application:
widget->show(); //Widget had to be shown
widget->createWinId();
sendWinId(widget->winId()); //Post window handle to master app where is constructed container
Master application:
QWindow* window = QWindow::fromWinId(clientWinId);
window->show(); //This show/hide toggle did trick in combination with show in client app
window->hide();
QWidget* container = QWidget::createWindowContainer(window, parentWindowWidget);
After this I was able to control window properly through QWidget container.

Default lock screen comes up in few devices after my lock screen app

I have disabled the default pattern/PIN lock using the following code in my lock screen app.
KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
k1 = km.newKeyguardLock("IN");
k1.disableKeyguard();
Also, i have used the FLAG_DISMISS_KEYGUARD.
It is working fine in my Moto G. But, few devices are showing the default Pattern lock after my lock screen. How can i fix it? What could be the issue?
Besides FLAG_DISMISS_KEYGUARD, you may need:
FLAG_KEEP_SCREEN_ON,
FLAG_SHOW_WHEN_LOCKED
and
FLAG_TURN_SCREEN_ON also.
i.e.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

Actionscript - Flex mobile thread while loading data?

I am using Flash builder actionscript 3 Flex mobile.
I have a very heavy function that loads data from the local device and creates many graphic elements. While this function runs, the device freezes for 6 seconds or so.
I want to show a progress bar and let the device continue working, is there any way I can use threading to do this ? Other ideas are also welcome.
Thanks, Koby.
You know that at which function application getting freeze. Before that function call a progress bar. Create a progress bar in a pop up mode & call it. After 6 seconds(Not recommended) or getting the data just call removeallpopups() method. So now you can set the label in progress bar as "Loding..."
Sample code
<mx:ProgressBar id="sampleProgressBar" styleName="Calib16Blue"
indeterminate="true" labelPlacement="left"
label="{theMessage}"/>
Call this mxml by creating a pop up.
To do 'proper' muiltithreading you need to use the Worker Class (Documentation here), however the SQLConnection class and FileStream class have asynchronous methods that fit into the normal Actionscript event listener cycle and operate in "the background". Allowing the rest of the app to load when they're still pending.

Application.GetResourceStream in non-ui thread

I have a problem with Silverlight application.
Suppose I have an xml file in resources stream. I get it as usual with something like this:
StreamResourceInfo sr =
Application.GetResourceStream(new Uri("uri goes there", UriKind.Relative));
var xml = XElement.Load(sr.Stream, LoadOptions.SetBaseUri);
And everything works just fine. But if the same code runs in the background thread (via async/await or, to be simple, in background worker) it always returns null.
I’ve heard about a bug in VS with similar problems (returning null) so I’ve tried to clean solution, delete obj folders etc. but nothing works — in background thread this code always return null for resources stream.
You can't access UI resources in background thread. Ideally you should access it in UI thread and pass it to background thread.

Sheet and thread memory problem

recently I started a project which can export some precalculated Grafix/Audio to files, for after processing.
All I was doing is to put a new Window (with progressindicator and an Abort Button) in my main xib and opened it using the following code:
[NSApp beginSheet: REC_Sheet modalForWindow: MOTHER_WINDOW modalDelegate: self didEndSelector: nil contextInfo: nil];
NSModalSession session=[NSApp beginModalSessionForWindow:REC_Sheet];
RECISNOTDONE=YES;
while (RECISNOTDONE) {
if ([NSApp runModalSession:session]!=NSRunContinuesResponse)
break;
usleep(100);
}
[NSApp endModalSession:session];
A Background Thread (pthread) was started earlier, to actually perform the work and save all the targas/wave file. Which worked great, but after an amount of time, it turned out that the main thread was not responding anymore and my memory footprint raised unstoppable. I tried to debug it with Instruments, and saw a lot of CFHash etc stuff growing to infinity.
By accident i clicked below the sheet, and temporary it helped, the main thread (AppKit ?) was releasing it's stuff, but just for a little time.
I can't explain it to me, first of all I thought it was the access from my thread to the Progressbar to update the Progress (intervalled at 0,5sec), so I cut it out. But even if I'm not updating anything and did nothing with the Progressbar, my Application eat up all the Memory, because of not releasing it's "Main-Event" or whatsoever Stuff.
Is there any possibility to "drain" this Main thread Memory stuff (Runloop / NSApp call?). And why the heck doesn't the Main thread respond anymore (after this simple task) ???
I don't have a clou anymore, please help !
Thanks in advance !
P.S. How do you guys implement "threaded long task" Stuff and updating your gui ???
while (RECISNOTDONE) {
if ([NSApp runModalSession:session]!=NSRunContinuesResponse)
break;
usleep(100);
}
Is there a reason you're doing that? A sheet will block its parent window without you having to do anything like this. You can prevent quit within your app delegate.
If you really do need the above code for something, try creating an autorelease pool before sending the runModalSession: message, then draining it after (but before you compare to NSRunContinuesResponse and break).

Resources