currently i am working with the project in C# WPF with entity framework, i had used MahApps.Metro package for UI, i need to implement the ProgreeBar or LoadingIndicator or anything that idicates that my app is not stuck,
Whenever i made any kind of operation first time, my apps stucks for few second and it seems like its hang,
In web apps i had implemented AJAX call, loading process with
.ajaxStart()
.ajaxStop()
So my question is does anyone know or is there any way to implement every call of app or entity framework or any process how can i implement ProgressBar or GIF Loader or anything that shows process.
I had tries ProgessBar of MahApps.Metro but whenever I start that ProgressBar it Stucks untill that process complete.
EDITED:
Some of Code is,
private void ShowClientWindow(object sender, RoutedEventArgs e)
{
myProgess.IsIndeterminate = true; //its for progressbar
myFrame.Source = new Uri("MyViews/ClientView.xaml", UriKind.Relative);
myProgess.IsIndeterminate = false;
}
Thanks,
Gaurav Oza
The solution is not to display a ProgressBar to let the user think the application is not stuck, but to use async calls to actually avoid being stuck.
Entity Framework 6 does support async query and save
Related
I just started learning UWP and i'm really confused on how it works. I already saw tens of posts that talk about my problem but can't figure out how to do what I want.
So I want to make an app that runs on windows startup, I want the app to be not visible so it needs a background Task, how can I trigger this background task without getting to the app UI ?
The app is supposed to have the Background Task always running, and its interface is supposed to be used as "settings" so I don't need the app to be shown on startup.
Thanks.
I found my way here after a lot of googling. to be honest I have come to the same conclusion as Motaz. But as of writing this I am way too invested in what I have already. While what I have here is not the perfect answer to his question. I wanted to come back and post what I've learned for anyone else who ends up here.
My need is a app that when started will monitor a third party USB device until the app is closed (regardless of whether the app is minimized or not)
Windows Template Studio is good, but the docs not so much. Especially when it comes to Background tasks.
I started here: https://github.com/Microsoft/Windows-universal-samples. But there is two problems.
They combined all the examples and some of the code is shared, which makes it difficult to pull a project out and hack it apart without breaking the original examples.
Following their background task example I perpetually had issue with the manifest and and it wanting an audio task
I went back to the template studio and created the simplest version with a background task possible. After a lot of trial and error I got something that works. I have posted it here: https://github.com/PillarOfSociety/WindowsTemplateStudio-BackgroundTask
Some things to note:
I am no expert on UWP and while this runs I have no intent on putting it in the store nor did I try.
If you do download my project and run it, you should be able to just hit the "Add events" and the "Start Back" button and the task should run and update the Progress bar.
I used an ApplicationTrigger. the original example from the template uses a TimeTrigger which takes time in MINUTES (took me too long to figure that out). Supposedly Application triggers have a 30sec timeout.. but on my laptop they live for much longer.. I don't know how long. This page is useful: https://learn.microsoft.com/en-us/windows/uwp/launch-resume/support-your-app-with-background-tasks
The template studio generated BackgroundTaskService will leave background tasks registered after the app is closed, but will NOT make the connection back to them once its rerun, so on a rerun either the task appears not to run, or will crash the app when triggered.
Important Code I discovered:
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
TestText += task.Value.Name; //gets the typename of the task
//task.Value.Unregister(true); //will unregister tasks
}
await Task.CompletedTask;
The tasks in BackgroundTaskRegistration.AllTasks are not the BackgroundTask class that the template studio uses. IN my example I unregister all of them each time it runs so that you have a reference to the task as an instance of BackgroundTask.
Hopefully this helps someone and Good luck!
If you're just starting out use Windows Template Studio, it will be perfect for you. It is an extension of Visual Studio which lets you create new uwp projects with a lot of built in features, and you can only choose the features you want. It will save you a lot of time on basic stuff.
https://github.com/Microsoft/WindowsTemplateStudio
I have a C++ application (calling functions of an SDK for a specific hardware component), and want to display its data in a C# GUI. The C# part is a DLL which the C++ calls. (This is by request from the customer so I don't have much choice about it.)
I'm not very well versed in C#, so might be missing something obvious, but I'm running into problems both displaying the GUI and updating it.
I access the C# code using this method, with code roughly like this (ptr is a class variable):
// Initialize COM.
CoInitialize(NULL);
ptr = new IPtr(__uuidof(ManagedClass));
(*ptr)->ShowForm();
then in another thread:
if (updating) (*ptr)->Update(data)
On the C# side we have:
FormClass myForm;
void ShowForm()
{
myForm = new FormClass();
Application.Run(myForm);
}
void Update(Data data)
{
myForm.Update(data)
}
When I use Application.Run or ShowDialog to show my GUI, the form shows nicely but the update makes the application crash. Using Show has the GUI get stuck. Using BeginInvoke resulted in the GUI never appearing.
Is there any recommended way for me to start the GUI given this setup? Would it help to somehow use Invoke/BackgroundWorker in Update rather than calling myForm's method directly?
You must update C# GUI on the the UI thread. See this answer for how to synchronize from another thread to the GUI thread.
C# Windows Forms Application - Updating GUI from another thread AND class?
You might also find the Debug Location toolbar handy to determine what thread you are currently in when debugging in Visual Studio
https://blogs.msdn.microsoft.com/davedev/2012/07/18/where-is-the-suspend-resume-and-terminate-toolbar-in-visual-studio-2012-ultimate/
In a splash screen for an iOS app written in MonoTouch C# I am calling a number of web services which then calls another web service until all the data I need has been collected for the app to run. I am doing this asynchronously so that I can display an activity indicator to the user.
However I feel like the code is very messy and all these calls and callbacks are in the ViewController. I would like a way of separating this so that the ViewController only cares about the results coming back but I would need a way for the ViewController to stop until the call has completed.
At the moment, my code looks a little something like this:
protected void FirstServiceCompleted(object sender, FirstServiceCompletedEventArgs e)
{
// Do something
_servicesHelper.GetSecondService(GetSecondServiceCompleted);
}
protected void SecondServiceCompleted(object sender, SeconServiceCompletedEventArgs e)
{
// Do something else
_servicesHelper.GetThirdService(GetThirdServiceCompleted);
}
... etc
It would be nice to have a way which through another object my ViewController retrieves the data from the event args while behind the scenes I use this code. At the end of all these calls I change to a new view to show the main home screen with this data populated. However my ViewController seems very bloated and there's a lot of repetitive calls like this.
Any help or advice would be very much appreciated.
I think it might be useful for you to look at the TPL - Task Parallel Library - this tackles exactly the sort of async processing you are talking about.
Using Task along with ContinueWith and WaitAll, I'm sure you'll find a way to clean up your code flow.
If you search you'll find hundreds of getting started links for this - eg http://www.codeguru.com/columns/experts/article.php/c17197/Understanding-Tasks-in-NET-Framework-40-Task-Parallel-Library.htm
Built on top of the TPL, in the near future you will also be able to use the new await/async features of c# - but these aren't available today for MonoTouch.
I'm wondering what the best approach might be for what I'm trying to do. My application has a button that starts a background download operation, and then performs some actions dependent on the downloaded files.
It's like a "The game will begin shortly once necessary data is downloaded" situation, where the user may still use the main form.
private void btnStart_Click(object sender, EventArgs e)
{
//execute some code
Downloader.RunWorkerAsync(files); //this worker reports progress to the main form
while (Downloader.IsBusy)
Application.DoEvents();
//execute some more code
}
I'm aware that doing it that way is not good at all.
I cannot execute the download code synchronously, because the main form needs to remain responsive during the download operation.
I also cannot put the final code into the download completed event, as it is used by many other areas of the program and must remain a "generic" download system.
So, is there a way to do what I want? I do not have any experience with other async methods.
If you use BackgrounWorker you must configure it properly. BW has RunWorkerCompleted event to which you must subscribe to handle completion of you async work.
I think you should use asynchronous programming features of the .net 4.5 framework (await and async).
refer to async programming
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why is Application.Restart() not reliable?
I pulled the code straight from MSDN. This updates my application, but Restart() does not work. The application shuts down, but it does not restart.
I added a MenuItem to my Form to validate that Restart() works at all:
private void restartToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Restart();
}
This will restart the application (of course, it performs no updates and is user initiated, so it is fairly useless).
I have nothing else going on with this application. No event handlers for the Form on shutdown, nothing. This is the most basic Windows Forms application I could build (it just displays a resource JPEG in an ImagePanel).
Why does Restart() not work here?
Is your application Windows Forms or WPF? Because Application.Restart only exists in the Windows Forms Application object (System.Windows.Forms.Application) and is not supported by applications running under the WPF Application (System.Windows.Applications). You can still call it, but as the application context is different, it doesn't work.
If you are using a Mutex, or something of the like to ensure only one instance of the application is running at a time, that be causing this issue.
Try wrapping it with a BeginInvoke just in case it's not on the main STA thread.
Are you sure that you're calling Application.Restart from the main form? If you call a form with .ShowDialog and then from that form call Application.Restart, it won't work because the .ShowDialog causes the dialog form to run on a separate thread.
Try to raise a new process, maybe that can workaround it:
Process.Start(Application.ExecutablePath);