I want to write some numbers from textbox1 to Text1.text file and Immediately after that read the number from Text1.text and show it in textbox2. I write this code in 2 btn.
I use the below code:
Now I want to use 2 thread in my code:
1. the first one is inserted the number from textbox1 to a txt file
2. sleep the first thread
3. immediately the second thread run and read that number from the file or the first thread. I don't know how can I do this in vb.net web form?!
And also I don't know how to use thread in my code:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestThread.aspx.vb" Inherits="WebAppAwaitVB.TestThread" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="lblWrietToFile" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Write to file" Width="129px" />
<br />
<br />
<br />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="lblError" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Button ID="Button2" runat="server" Text="Read From File" />
<br />
</div>
</form>
</body>
</html>
Imports System.IO
Public Class TestThread
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Public Sub WriteToFile()
Using writer As New StreamWriter("E:\Text.txt", True)
Dim strNumOne As String = textbox1.Text
writer.WriteLine(strNumOne)
End Using
End Sub
Public Sub ReadFromFile()
' Store the line in this String.
Dim line As String
' Create new StreamReader instance with Using block.
Using reader As StreamReader = New StreamReader("E:\Text.txt")
' Read one line from file
line = reader.ReadLine
End Using
' Write the line we read from "file.txt"
TextBox2.Text = line
Console.WriteLine(line)
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
WriteToFile()
lblWrietToFile.Text = "Write To File has been finished...!"
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ReadFromFile()
End Sub
End Class