Это код. Page_Load продолжает работать, и мне нужно, чтобы он запускался только один раз. Когда я отлаживаю, моя page_load продолжает срабатывать
<%@ Page Language="vb" AutoEventWireup="False" CodeBehind="helloworld.aspx.vb"
Inherits="WebApplication9.helloworld" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="btnSubsribe" runat="server" Text="Subscribe" />
<br />
<asp:TextBox ID="TextBox2" runat="server" Width="281px"></asp:TextBox>
<br />
<br />
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox4" runat="server" Width="303px"></asp:TextBox>
<br />
<br />
</div>
<asp:Timer ID="Timer1" runat="server">
</asp:Timer>
</form>
</body>
</html>
VB Code:
Imports System
Imports uPLibrary.Networking.M2Mqtt
Imports uPLibrary.Networking.M2Mqtt.Messages
Imports System.Text.Encoding
Public Class helloworld
Inherits System.Web.UI.Page
Private Publisher As MqttClient = Nothing
Private Subscriber As MqttClient = Nothing
Private msgTime As String = ""
Private msgDate As String = ""
Const TIME_ID As String = "/CPM/Time"
Const DATE_ID As String = "/CPM/Date"
Const MATH_ID As String = "3.14"
Const DefaultInteger As Integer = 100
Const MyLong As Long = 45L
Const MySingle As Single = 45.55!
Const MyCharacter As Char = "a"c
Я пытался изменить дескрипторы Page_Load, но он все еще не работает
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Publisher = New MqttClient("telemetry")
Dim b As Boolean = CBool(Publisher.Connect(Guid.NewGuid.ToString))
Timer1.Interval = 2000
Timer1.Enabled = True
End Sub
Protected Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim dt As DateTime = Now
TextBox1.Text = dt.ToString("hh:mm:ss.fff")
TextBox3.Text = dt.ToString("MM/dd/yyyy")
Dim ppreturn1 As UShort = Publisher.Publish(TIME_ID, UTF8.GetBytes(TextBox1.Text))
Dim ppreturn2 As UShort = Publisher.Publish(DATE_ID, UTF8.GetBytes(TextBox3.Text))
'Dim ppreturn3 As UShort = Publisher.Publish(MATH_ID, UTF8.GetBytes(TextBox1.Text))
'Dim ppreturn4 As UShort = Publisher.Publish(DefaultInteger, UTF8.GetBytes(TextBox1.Text))
'Dim ppreturn5 As UShort = Publisher.Publish(MyLong, UTF8.GetBytes(TextBox1.Text))
'Dim ppreturn6 As UShort = Publisher.Publish(MySingle, UTF8.GetBytes(TextBox1.Text))
' Dim ppreturn7 As UShort = Publisher.Publish(MyCharacter, UTF8.GetBytes(TextBox1.Text))
TextBox2.Text = msgTime
'TextBox3.Text = message
TextBox4.Text = msgDate
'TextBox5.Text = message
'TextBox6.Text = message
'TextBox7.Text = message
'TextBox8.Text = message
End Sub
Protected Sub btnSubsribe_Click(sender As Object, e As EventArgs) Handles btnSubsribe.Click
Subscriber = New MqttClient("telemetry")
Dim b As Byte = Subscriber.Connect(Guid.NewGuid.ToString)
btnSubsribe.Enabled = False
Subscriber.Subscribe(New String() {DATE_ID, TIME_ID}, New Byte() {MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE})
'Subscriber.Subscribe(New String() {TIME_ID}, New Byte() {MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE})
AddHandler Subscriber.MqttMsgPublishReceived, AddressOf Client_recievedMessage
End Sub
Protected Sub Client_recievedMessage(ByVal sender As Object, ByVal e As MqttMsgPublishEventArgs)
Dim s As String = System.Text.Encoding.[Default].GetString(e.Message)
Select Case e.Topic
Case DATE_ID
msgDate = s
Case TIME_ID
msgTime = s
End Select
End Sub
End Class
Это приложение таймера, которое работает на инте rnet. В нем использовался таймер, который используется в визуальном исследовании ios. Asp. net page_load
функция загружается дважды, следовательно, это влияет на производительность моей страницы. Кто-нибудь знает причину, по которой он загружается более двух раз.