|
Hi,
On my Win Form App, I'm starting a new thread for my Splash Screen (and when loading some component on my main form).
I wanna be able to update a label on the new thread. I try with invoke, delegate and similar thing but i'm not able to do it.
I'm now out of ressource. Can anyone help me with this ? May be my code is not the best to do this ?
The frmSplashScreen form containt a label name metroLabel4 and this is the one I want to update from the other form (when I load the component, where the "// Code for loading component go here" is.
Thanks in advance
public frmMain()
{
Thread t = new Thread(new ThreadStart(Loading));
t.Start();
InitializeComponent();
t.Abort();
}
void Loading()
{
frmSplashScreen frm = new frmSplashScreen();
Application.Run(frm);
}
|
|
|
|
|
How many times do you want to "update" the label? If it's only once, pass the text for the label in the splash form's constructor. And why you just don't "show" the splash screen escapes me; A splash screen usually doesn't "do" anything except keep the user from thinking the app is hung. Add a timer to the flash form if you want it to animate something. Use a concurrent collection (queue) or an observable collection if you want to share information.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hello!
Update should be like 4 or 5 times. As a beginner, that's the tutorial I find that make it run insted of showing it.
I try to add a timer but don't know why, the splash screen don't show when I have it.
Thanks!
|
|
|
|
|
Firstly, you shouldn't be calling Application.Run yourself - you should only have the one message loop. I'm not sure what effect that would have, since there can only be one MainWindow object, and that's already in use ... if that worked (which it doesn't) then your thread Abort would either kill the main form and app, or possibly make it impossible to exit the main process properly at all.
Secondly, you can't update a control except from the thread on which it was created - normally the one and only UI thread - so accessing the label on the splash form is going to be problematic - if you could find it, which you can't since the only reference you have is local to the loading method.
The normal way to do this is to Show the Splash screen, and move the long running task to a background thread, which updates the splash screen via progress reports to the UI thread - and I'd move the "loading" code into the Form.Load or Form.Shown event handlers instead of in the main form constructor and use a BackgroundWorker class instance to offload the long job to a second thread, using the Progress reporting of that class to get information back to the UI thread.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hello!
I'm a beginner and I follow a tutorial for creating the splash screen. Event if I call the APplication.Run myself, it work's and the abord only exit the splash screen.
How can I move the long running task to a background thread ? I'm a bit lost
Thanks!
|
|
|
|
|
That's fairly easy:
private void FrmMain_Shown(object sender, EventArgs epp)
{
BackgroundWorker work = new BackgroundWorker();
work.DoWork += Work_DoWork;
work.ProgressChanged += Work_ProgressChanged;
work.RunWorkerCompleted += Work_RunWorkerCompleted;
work.WorkerReportsProgress = true;
work.RunWorkerAsync("A parameter of any type you want to pass it");
}
private void Work_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
MyTextBox.Text = "Done.";
}
private void Work_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
MyTextBox.Text = ($"Progress: {e.ProgressPercentage} - {e.UserState as string}");
}
private void Work_DoWork(object sender, DoWorkEventArgs e)
{
if (sender is BackgroundWorker work)
{
for (int i = 0; i < 1000000; i++)
{
Thread.Sleep(1000);
work.ReportProgress(i / 10000, $"An object of any type you want to pass back to the main thread: {i}");
}
}
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
DoWork runs for a million seconds.
for (int i = 0; i < 1000000; i++) {
Thread.Sleep(1000);
work.ReportProgress(i / 10000, $"An object of any type ...: {i}");
}
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
It's a long running job!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Trying to extend tutorial code without first studying the basic aspects of the topics it covers is, usually, going to result in problems. In this case, we can't "see" the tutorial, and be more specific.
There are lots of good resources for understanding threading in C#; for specific issues, like thread-thread interaction, and UI thread interaction with created threads, start here: [^], and, [^]
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Hi.
I have created an app that modifies the config file of another app and modifies some data in SQL Server. I'm using Visual Studio 2019 with forms in C# . When I run it in my computer it works fine, but when I run it on another computer (without Visual Studio) it gives the message: "To run this application you must install .NET. Would you like to download it now?"
Does anyone know what I must include in my app to resolve this issue?
Thanks.
|
|
|
|
|
It's telling you to install the .NET Framework version you wrote the app against.
|
|
|
|
|
|
The obvious requirement is to install the framework and other essentials the development machine uses on the 'other' machine. Strategies;
1) synchronize windows updates: as of the May 2019 update Win 10 includes FrameWork 4.8
2) get the 'other' machine user to install the missing whatevers, which may require power-user skills and access permissions: [^]
3) use an installer that will ensure the missing whateve4s are installed, like ClickOnce [^] , or, dotNetInstaller [^], or a commercial installer like InstallShield.
3a) compare ClickOnce with the Win installer: [^]
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
If you are using .NET Core or .NET 5 or 6 you can create a self-contained exe which includes all of the .NET Core/5/6 framework required.
"Time flies like an arrow. Fruit flies like a banana."
|
|
|
|
|
I want to make a virtual camera with C#. It will pass the images it takes from the camera through a few simple filters. Other programs (like Zoom, Skype) will see it as a camera. Is it possible to make such a program?
|
|
|
|
|
Maybe this is a reasonable starting point:
[^ DirectShow Virtual Video Capture Source Filter in C#]
It doesn't read from a camera, but will give you some idea on what is required. It's quite old, so might not be up-to-date, but if nothing else it might give you some words to google for newer examples.
I would not recommend this for a beginner.
|
|
|
|
|
It's been done. Search for virtual camera / webcam "drivers".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
HI,
I am curios to know all the new features introduced in .net core & in c# regarding various version. i was searching this site to get few good article on this topic but no luck. so anyone can share few links of good codeproject articles which talk about C# & .Net core new features version wise and their advantages with example code to show usage.
Thanks
|
|
|
|
|
|
Hi, i find Jonathan Allen's articles on InfoQ about new C# features very helpful: [^], [^]. Some of Steve Gordon's posts also: [^], and [^]
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 21-Oct-21 6:29am.
|
|
|
|
|
Hi,
I want to ask how to send a messages to a customer WhatsApp from windows forms applications.
Please hep me ASAP
Thank You
|
|
|
|
|
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
A very quick search using your subject as the search term gave 11 million results, including document,s videos, and source code: send a messages to a customer WhatsApp from windows forms applications - Google Search[^]
In future, please try to do at least basic research yourself, and not waste your time or ours.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
I did many search but all of them is third-party apis, I need a free one if it is available
Thank You
|
|
|
|
|
There isn't a free client API for WhatsApp.
You need a business account with a line of credit.
|
|
|
|
|
Hello friends, I want to do SQL Dependency capability in a database file without SQL management The default file address is also in (c:\database.mdf)
I run the service broker in the file, unfortunately I apply a record in the database, it will not be updated in another system, please help
|
|
|
|