Rectangle 27 11

You never want to call thread.sleep() on the UI thread as it sounds like you have figured out. This freezes the UI and is always a bad thing to do. You can use a separate Thread and postDelayed

This SO answer shows how to do that as well as several other options

java - How can I wait for 10 second without locking application UI in ...

java android wait
Rectangle 27 11

You never want to call thread.sleep() on the UI thread as it sounds like you have figured out. This freezes the UI and is always a bad thing to do. You can use a separate Thread and postDelayed

This SO answer shows how to do that as well as several other options

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

java - How can I wait for 10 second without locking application UI in ...

java android wait
Rectangle 27 17

View models are specific to the particular application. I guess that the view models would differ between your web application and your console application. So have each application define its own view models and the corresponding mapping between the domain models and the view models. Don't have your domain models posses methods that convert them to view models because this way you are completely tying your domain layer to the UI layer which is the worst thing to happen. Use a mapping layer (which will be specific to each application type). AutoMapper is a great example of a mapping layer that you could have.

Don't even try to reuse ASP.NET MVC view models in a console application. As you have already found out they will contain references to System.Web.Mvc because for example a dropDownList in ASP.NET MVC is represented with the IEnumerable<SelectListItem> class whereas in a Console Application, god knows, maybe an IEnumerable<SomeItemViewModel>.

Conclusion: View models and mapping back and forth between the domain and view models belong to the UI layer (a.k.a ASP.NET MVC, Console, WPF, ...).

I am not trying to use my viewmodels in my console app. I am simply trying to move as much of my MVC code as possible outside the MVC project. I guess you are questioning the value of doing that. So if this code is in my MVC project where would it go (in the controller?, in another class?)

If it is MVC code, then it definitely should stay in your MVC application. Or in a separate assembly that has dependency on System.Web.Mvc but which you shouldn't be trying to reuse in other projects. What you should reuse is your domain models and business logic. That's something that could easily be moved to a separate layer which has no dependencies on MVC.

i updated the question to highlight one particular example where i send out emails from my console app and since the email data is almost identical to one of my views, i would like to leverage that ViewModel code. Clearly i don't need SelectListITem in my console app but the viewmodels that are just containers of various data and methods ideally should be reused . .

I wouldn't try to reuse any view models between different types of applications. You could have some base view models that do not contain view specific types and then have the actual view models derive from those base classes and add the specific types to the corresponding view.

In your first comment you state that "I am not trying to use my viewmodels in my console app" yet the second comment states "since the email data is almost identical to one of my views, i would like to leverage that ViewModel code". This appears to be a contradiction.

c# - How can I refactor my database access code outside my MVC project...

c# asp.net-mvc model-view-controller refactoring asp.net-mvc-viewmodel
Rectangle 27 1

See the SwitchUserSample in the Facebook SDK for iOS for an example of how to do this. If you do this, you should have some UI in your application that provides users the ability to choose between logging in via the facebook application or logging in as a different user.

thanks, that what i'm looking for.

ios - How can I link my app to a Facebook id different from the id in ...

ios facebook facebook-graph-api facebook-ios-sdk
Rectangle 27 0

ItemsControl
VirtualizingStackPanel
ItemsPanelTemplate

I have a whopping 15 items in the control. Like I said, there's no way the CPU is working hard at figuring where to put 30 rectangles. Also, I finally got access to another machine that I could put this app on, and it rendered with no visible delay.

wpf - How can I diagnose hangs on the UI thread in my application? - S...

wpf performance rendering
Rectangle 27 0

From you answer its not very clear what your problem is. A simple, but often sufficent solution is to change the look and feel for you application to the Systems default look an feel (so Swing looks just like a native application). All you need to do is insert the following code somewhere before any of your UI is created/shown (if you don't know where, place it as the first in your main-method):

try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
// exit application, log  or ignore exception
}

java - Can we develop very good looking UI in swing and if not what ar...

java swing desktop-application javafx look-and-feel
Rectangle 27 0

I'd suggest developing your application in such a way that you use a single controller to return the initial application assets (html, javascript, etc) to the browser. Create your API / logic in WebAPI endpoint services and access those services via JavaScript. Essentially creating a single page application. Using MVC 4 our controller can return different Views depending on the device (phone, desktop, tablet), but using the same JavaScript all of your clients will be able to access the service.

asp.net mvc - How can I write an MVC3/4 application that can both func...

asp.net-mvc asp.net-mvc-3 rest asp.net-web-api
Rectangle 27 0

You could always create Custom Exceptions for your application, have your Business Layer throw those Exceptions when an error occurs, and then have your UI/Consumer properly handle those Custom Exceptions.

[Serializable]
public class EmailValidationException : Exception
{
    // overriden constructors would go here

    private List<string> _validationMessages = new List<string>();

    // store your validation exception messages in a collection
    public ReadOnlyCollection<string> ValidationMessages 
    {
        get
        {
            return _validationMessages.AsReadOnly();
        }
    }
}

@Justin Niessner - You would create a class like this for every type of validation or a generic error class/collection that can be reused. I am pretty new to .Net.

c# - How can I pass error and other messages up from the DAL / Busines...

c# asp.net
Rectangle 27 0

Why do you want this information? Typically when people ask this question it's because they want to ensure that their UI is in the foreground if it's not. And that usually is what happens just before they try to steal the focus away from the application which does have the foreground.

Having said that, either of the two techniques above would work - I think I'd prefer the EnumWindows/GetWindowRect/IntersectRect technique in Steve Gilham's answer.

c# - How can I find out if there are windows above a control? - Stack ...

c# .net windows winapi
Rectangle 27 0

Find place where your UI is being modified on background thread and also pushing View Controller on navigation stack from background thread causes this error, posting that code on main thread will fix it.

ios - Xcode 7: This application is modifying the autolayout engine fro...

ios xcode autolayout xcode7
Rectangle 27 0

Your android application consist of process, services, threads, message queues. It application developer choice when to use what. As good developer, you should always try to make you application user experience smooth without and any hang. Always perform heavy/time consuming activity with service or async threads, and avoid such activity on main thread as it cause UI hangs.

can you explain the difference between process and async threads? Say i launch angry birds. Would the game(application itself) be the process? Would the background music be running as a service or its own async thread?

both AsyncTask and thread can be treated as similar,but developer should know where to use what... Async Task should be used for task which can be accomplished withing few miliseconds, whereas threads can be used to more time consuming task e.q downloading/high CPU task. Yes, every application have minimum one process.For good user experience you should always avoid putting everything in main process/thread, make use of service, process and threads

android - Can anyone confirm my example of a background vs foreground ...

android linux multithreading process
Rectangle 27 0

The AppHangB1 event is triggered when the UI thread doesn't respond to messages for several seconds and the user tries to terminate it. Hangs can be caused by just about anything: busy loops in your code, doing network or disk I/O on the UI thread, the UI thread being blocked on a lock held by a background thread doing a long running task, etc.

It's a bit concerning that Visual Studio can't break at the point of the hang. Are you attaching for managed-only debugging or for mixed-mode debugging? You could try using Windbg (http://www.microsoft.com/whdc/devtools/debugging/default.mspx) to non-invasively attach to the process and try to get a stack trace of the hung thread (you want to look at using !clrstack to get the managed stack trace). The learning curve for Windbg is pretty steep, so you might just want to collect a dump that you can debug in Visual Studio.

My debugging skills don't extend much beyond the VS2008 tools. I have used WinDbg in the past, but am not very familiar with it. I am unable to get a trace (in VS or WinDbg) on the occasion that the app does hang. Both debugging apps hang when my app hangs. Any suggestions on how to get a trace?

Try remote debugging. If your app is doing some very strange and horking the desktop, doing a remote debug might help since it's UI couldn't be hung by your app.

.net - What can cause a WPF application to crash with an AppHangB1 Pro...

.net wpf debugging crash
Rectangle 27 0

I'm creating an entire desktop application with a single WebView, it is available at github. Basically it's UI is a single HTML file which links a dozen of JS files. To call Java from JS I wrap my requests into json and call a Java facade bean. It is also possible to call JS from Java in same fashion. Though it is possible to call Java directly by invoking a method on a Java bean with parameters of any type, I did have a few application crashes after which I decided to make it completely safe and stay with json. This app uses AngularJS and Twitter Bootstrap to render pages.

I had created a ticket in Oracle's JIRA for better Java integration (JSR-223) inside a WebView and their answer was it could be scheduled for Java 9.

The development is pretty fast, when the process is set up - it's hard to debug the app in the beginning because there is no debugger. Some top-level JS exceptions are not being caught as well. At the moment I'm having no issues with WebView in JavaFX 8. JavaFX 7 is unusable for me because of the problem with fonts.

Answering your last question - I have no idea, but the situation is completely the opposite. For some reason Oracle puts resources for JavaFX native components development, but not for better WebView integration.

How can I use HTML & CSS to create the user interface for my java app?...

java html css user-interface javafx
Rectangle 27 0

Here's an example of how to use Invoke to change to the UI thread, where it is safe to access controls:

// In some form method, setup the event handler
algorithm.ProgressChanged += new EventHandler(AlgorithmProgressChanged);

private void AlgorithmProgressChanged(Object source, EventArgs args)
{
    if (this.InvokeRequired)
    {
        // Switch to the UI thread
        this.Invoke(new EventHandler(AlgorithmProgressChanged), source, args);
        return;
    }
    // It should be safe to set the progress beyond this point.
    progressBar.Value = algorithm.Progress;
}

c# - How can I use multithreading in a Windows Forms application to up...

c# .net events multithreading handler
Rectangle 27 0

No. The UI needs to be on the main thread. You can do things in the background with NSOperation or other means and update the UI be doing performSelectorOnMainThread The UI itsel relies on the application run loop.

I understand that it relies on the application run loop, but I don't see why that should be an issue. You can create a NSRunLoop on just any thread.

@zneak: Off the top of my head, there's the fact that Apple Events are delivered to the main thread's run loop. Opening a document in your app from (e.g.) the Finder, activating your app via the Dock, and reopening your app when the user launches it while it's already open are all Apple Events, and they will be delivered on the main thread, so AppKit's standard handlers must also be registered on the main thread.

multithreading - Can the UI be run from a secondary thread? - Stack Ov...

multithreading cocoa
Rectangle 27 0

You must do it in another Thread, in this way the UI will not block and not become irresponsive.

Meanwhile you can show an activity indicator using a progress dialog. and when the process is done hide it.

Beware with UI operations in cross-threading.

c# - How can I stop this application from showing as not responding? -...

c# android xamarin
Rectangle 27 0

For controls and panels, there is a huge difference between Visibility.Collapsed and Visiblity.Hidden. Hidden reserves the space of the invisible element, Collapse frees the used space. This can make a big difference in an UI.

Using the same enumeration for the visibility of the window-class is IMO first of all a question of holding a constancy in the class-library, but may be it makes also some other finer differences.

If there is a possibility to directly restart the app, I don't know. What you can try is to use App.Current.Shutdown() to close the app and start a new instance through System.Diagnostics.Process.Start() where the path to the app can be taken from System.Reflection.Assembly.GetEntryAssembly(). `.

How can I restart WPF application? - Stack Overflow

wpf
Rectangle 27 0

If you have some initializing that takes a long time then it's best to run it in a new thread (via performSelectorInBackground:withObject:). Your UI would then start in some "locked" state. Create a method that "unlocks" the UI. As the very last action of your background method, run that unlock method via performSelectorOnMainThread:withObject:waitUntilDone:.

It's important not to block the main thread so that the run loop can respond to iOS events. That's why you should avoid sleep or other blocking stuff. It's alright to block in another thread, though. Also, adapting event-based programming methods help a lot.

performSelectorInBackground:withObject:
NSAutoreleasePool
dispatch_async

i'll try that, i'll take the splash screen and put it as main screen, then add indicator view. and run the loading of images in the background like you said, and then coming back at you. Thanks a lot,

Splash screen is fine, but I'd suggest adding an UIActivityIndicatorView (aka "spinner") to show that something is happening.

Ah yes. You need to set up an autorelease pool in the background method. See for example this or this question.

dispatch_async only starts a new thread (which might be costly) if GCD thinks there is a need to, otherwise it reuses one from its thread pool. performSelectorInBackground:withObject: always creates a new thread. Also, dispatch_async is more flexible (you might be able to skip creating a new method which you would've needed for performSelectorInBackground:withObject:).

I recommend watching the WWDC videos on topics that are interesting to you, you learn a lot of useful stuff there. Apart from that: experience ;-) Ran into problems, tried to solve them, learned stuff on the way.

Iphone, how can i avoid the watchdog killing my application for taking...

iphone watchdog
Rectangle 27 0

See the SwitchUserSample in the Facebook SDK for iOS for an example of how to do this. If you do this, you should have some UI in your application that provides users the ability to choose between logging in via the facebook application or logging in as a different user.

thanks, that what i'm looking for.

ios - How can I link my app to a Facebook id different from the id in ...

ios facebook facebook-graph-api facebook-ios-sdk
Rectangle 27 0

Any Java API/Library can be accessed from JavaFX - there is no limitation. You can do the UI of the application and core logic in JavaFX and use the existing Java Lib for printing stuff (the Print Service API might be a good start).

Doing this as an Applet might not be best idea, I would recommend using WebStart deployment.

is javafx needs kind of security something ? because i know that applet needed that.

java - can javafx print to dot matrix printer? - Stack Overflow

java grails printing javafx