© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
MotherBroker

❔ c# wpf textbox access violation

Hello does anyone know how can i edit the TextBox1.Text within the Task.run so i don't have an access violation ? here is the code :
private async void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Socket Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                Server.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 80));
                Server.Listen(2);

                Socket Client;

                await Task.Run(() =>
                {
                    Client = Server.Accept();
                    TextBox1.Text = "Hello";
                    
                });
            }

            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex);
            }
        }
private async void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Socket Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                Server.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 80));
                Server.Listen(2);

                Socket Client;

                await Task.Run(() =>
                {
                    Client = Server.Accept();
                    TextBox1.Text = "Hello";
                    
                });
            }

            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex);
            }
        }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ WPF textbox
C#CC# / help
3y ago
✅ WPF Masked TextBox
C#CC# / help
3y ago
WPF TextBox Binding
C#CC# / help
4y ago
❔ WPF Textbox decimal only
C#CC# / help
4y ago