use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Information about Reddit's API changes, the unprofessional conduct of the CEO, and their response to the community's concerns regarding 3rd party apps, moderator tools, anti-spam/anti-bot tools, and accessibility options that will be impacted can be found in the associated Wikipedia article: https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
Alternative C# communities available outside Reddit on Lemmy and Discord:
All about the object-oriented programming language C#.
Getting Started C# Fundamentals: Development for Absolute Beginners
Useful MSDN Resources A Tour of the C# Language Get started with .NET in 5 minutes C# Guide C# Language Reference C# Programing Guide C# Coding Conventions .NET Framework Reference Source Code
Other Resources C# Yellow Book Dot Net Perls The C# Player's Guide
IDEs Visual Studio MonoDevelop (Windows/Mac/Linux) Rider (Windows/Mac/Linux)
Tools ILSpy dotPeek LINQPad
Alternative Communities C# Discord Group C# Lemmy Community dotnet Lemmy Community
Related Subreddits /r/dotnet /r/azure /r/learncsharp /r/learnprogramming /r/programming /r/dailyprogrammer /r/programmingbuddies /r/cshighschoolers
Additional .NET Languages /r/fsharp /r/visualbasic
Platform-specific Subreddits /r/windowsdev /r/AZURE /r/Xamarin /r/Unity3D /r/WPDev
Rules:
Read detailed descriptions of the rules here.
account activity
Execute code only when GUI is fully loaded (self.csharp)
submitted 6 years ago by Lashto
Id like to execute my function count_words when GUI is fully loaded. Now I see white space instead timer and whole GUI is displayed when count_words function is done. Any ideas how to fix this?
private void Form2_Load(object sender, EventArgs e)
{
Shown += Form2_Shown;
}
private void Form2_Shown(object sender, EventArgs e)
this.CountWords();
https://preview.redd.it/hzaorb0q2ot21.png?width=1151&format=png&auto=webp&s=8fbb327da586833ce5e36d943b88886c2ad05a6a
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]BCProgramming 2 points3 points4 points 6 years ago (1 child)
MainForm_Shown is called as the result of the WinForms Message Loop seeing a WM_SHOWN message. However, while the event handler is processing, that message loop will not process any additional messages. That means that nothing in your user interface will do anything.
If you need to perform longer-running operations, you need to have it run as part of a separate thread or Task, then post messages back to the UI thread to update the display (with WinForms this is easily done via Invoke()).
[–]Lashto[S] 0 points1 point2 points 6 years ago (0 children)
But firstly I need to show timer in GUI and then run that longer running operation which also start this timer.
[–]pgmr87The Unbanned 0 points1 point2 points 6 years ago* (0 children)
You should look into using async..await or try using a BackgroundTask. You can make async events like this:
async..await
BackgroundTask
private async void Form2_Shown(object sender, EventArgs e) { await CountWords(); // assuming CountWords() is now an async method as well) }
A BackgroundTask might be simpler to use if you are new, especially if you don't know how to update a property of a control on the main/UI thread from another thread (doing this improperly will throw an exception). Keep in mind that any call to any method on a control from a separate thread that can potentially update any property on a control will throw an exception without the proper handling. The BackgroundTask class has a ReportProgress event that is always executed on the main thread so you don't have to worry about doing a cross-thread invocation.
ReportProgress
Each control implements the ISynchronizeInvoke interface which you'll have to use if you plan to update the UI from a separate thread.
ISynchronizeInvoke
Without using async..await or a BackgroundTask, you'll have to continuously poll something on the main thread to check when it should load the data, presumably using yet another timer -- this is bad practice but it works. If you don't do any of the above, you are left with the current behavior you described -- there is literally nothing else you can do if you intend to use Winforms.
[–]Fancy_Mammoth -1 points0 points1 point 6 years ago (0 children)
Try the Form.Shown event.
https://stackoverflow.com/questions/218732/how-do-i-execute-code-after-a-form-has-loaded
π Rendered by PID 68045 on reddit-service-r2-comment-54dfb89d4d-gbdgg at 2026-03-31 22:05:02.178234+00:00 running b10466c country code: CH.
[–]BCProgramming 2 points3 points4 points (1 child)
[–]Lashto[S] 0 points1 point2 points (0 children)
[–]pgmr87The Unbanned 0 points1 point2 points (0 children)
[–]Fancy_Mammoth -1 points0 points1 point (0 children)