Interval









How do I use Interval
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: frmThiThat.cs Copy
301         private void timer1_Tick_1(object sender, EventArgs e)
302         {
303             timer1.Interval = 1000;
304
305             s--;
306             th--;
307             if (th == 0)
308             {
309                                     timer1.Stop();
310                     MessageBox.Show("Hết giờ làm bài!", "Thong bao");
311                     checkBox1.Checked = false;
312                     checkBox2.Checked = false;
313                     checkBox3.Checked = false;
314                     checkBox4.Checked = false;
315
316                     GhiLaiDapAnTS();
317                     SoCauDung = 0;
318                     for (int i = 0; i < SoCauHoi; i++)
319                     {
320                         if (BangDeThi.Rows[i][6].ToString().ToUpper() == BangDeThi.Rows[i][7].ToString().ToUpper())
321                             SoCauDung++;
322                     }
323                     int diem;
324                     diem = SoCauDung * 2;
325                     MessageBox.Show("Đúng " + SoCauDung.ToString()+" câu " + " Bạn được " + diem.ToString() + " điểm ");
326                     this.Close();
327
328             }
329             if (s == 0)
330             {
331                 p--;
332                 if (p == 0)
333                 {
334                     s = 60;
335                     th = s;
336                 }
337                 s = 60;
338             }
339
340                 lblHour.Text = h.ToString() + " : " + p.ToString() + " : " + s.ToString();
341
342             }
File name: PhotonHandler.cs Copy
24     public int updateIntervalOnSerialize; // time [ms] between consecutive RunViewUpdate calls (sending syncs, etc)
35     protected void Awake()
36     {
37         if (SP != null && SP != this && SP.gameObject != null)
38         {
39             GameObject.DestroyImmediate(SP.gameObject);
40         }
41
42         SP = this;
43         DontDestroyOnLoad(this.gameObject);
44
45         this.updateInterval = 1000 / PhotonNetwork.sendRate;
46         this.updateIntervalOnSerialize = 1000 / PhotonNetwork.sendRateOnSerialize;
47
48         PhotonHandler.StartFallbackSendAckThread();
49     }
File name: PhotonHandler.cs Copy
59     protected void Update()
60     {
61         if (PhotonNetwork.networkingPeer == null)
62         {
63             Debug.LogError("NetworkPeer broke!");
64             return;
65         }
66
67         if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated || PhotonNetwork.connectionStateDetailed == PeerState.Disconnected || PhotonNetwork.offlineMode)
68         {
69             return;
70         }
71
72         // the messageQueue might be paused. in that case a thread will send acknowledgements only. nothing else to do here.
73         if (!PhotonNetwork.isMessageQueueRunning)
74         {
75             return;
76         }
77
78         bool doDispatch = true;
79         while (PhotonNetwork.isMessageQueueRunning && doDispatch)
80         {
81             // DispatchIncomingCommands() returns true of it found any command to dispatch (event, result or state change)
82             UnityEngine.Profiling.Profiler.BeginSample("DispatchIncomingCommands");
83             doDispatch = PhotonNetwork.networkingPeer.DispatchIncomingCommands();
84             UnityEngine.Profiling.Profiler.EndSample();
85         }
86
87         int currentMsSinceStart = (int)(Time.realtimeSinceStartup * 1000); // avoiding Environment.TickCount, which could be negative on long-running platforms
88         if (PhotonNetwork.isMessageQueueRunning && currentMsSinceStart > this.nextSendTickCountOnSerialize)
89         {
90             PhotonNetwork.networkingPeer.RunViewUpdate();
91             this.nextSendTickCountOnSerialize = currentMsSinceStart + this.updateIntervalOnSerialize;
92             this.nextSendTickCount = 0; // immediately send when synchronization code was running
93         }
94
95         currentMsSinceStart = (int)(Time.realtimeSinceStartup * 1000);
96         if (currentMsSinceStart > this.nextSendTickCount)
97         {
98             bool doSend = true;
99             while (PhotonNetwork.isMessageQueueRunning && doSend)
100             {
101                 // Send all outgoing commands
102                 UnityEngine.Profiling.Profiler.BeginSample("SendOutgoingCommands");
103                 doSend = PhotonNetwork.networkingPeer.SendOutgoingCommands();
104                 UnityEngine.Profiling.Profiler.EndSample();
105             }
106
107             this.nextSendTickCount = currentMsSinceStart + this.updateInterval;
108         }
109     }
File name: PhotonNetwork.cs Copy
644     {
645         get
646         {
647             return 1000 / sendInterval;
648         }
649
650         set
651         {
652             sendInterval = 1000 / value;
653             if (photonMono != null)
654             {
655                 photonMono.updateInterval = sendInterval;
656             }
657
658             if (value < sendRateOnSerialize)
659             {
660                 // sendRateOnSerialize needs to be <= sendRate
661                 sendRateOnSerialize = value;
662             }
663         }
664     }
File name: PhotonNetwork.cs Copy
674     {
675         get
676         {
677             return 1000 / sendIntervalOnSerialize;
678         }
679
680         set
681         {
682             if (value > sendRate)
683             {
684                 Debug.LogError("Error, can not set the OnSerialize SendRate more often then the overall SendRate");
685                 value = sendRate;
686             }
687
688             sendIntervalOnSerialize = 1000 / value;
689             if (photonMono != null)
690             {
691                 photonMono.updateIntervalOnSerialize = sendIntervalOnSerialize;
692             }
693         }
694     }
File name: TimeKeeper.cs Copy
31         public int Interval { get; set; }
File name: TimeKeeper.cs Copy
39         {
40             get { return (this.IsEnabled && (this.shouldExecute || (Environment.TickCount - this.lastExecutionTime > this.Interval))); }
41             set { this.shouldExecute = value; }
42         }
File name: TimeKeeper.cs Copy
48         public TimeKeeper(int interval)
49         {
50             this.IsEnabled = true;
51             this.Interval = interval;
52         }
File name: ChatClient.cs Copy
94         public bool Connect(string address, ConnectionProtocol protocol, string appId, string appVersion, string userId, AuthenticationValues authValues)
95         {
96             if (!this.HasPeer)
97             {
98                 this.chatPeer = new ChatPeer(this, protocol);
99             }
100             else
101             {
102                 this.Disconnect();
103                 if (this.chatPeer.UsedProtocol != protocol)
104                 {
105                     this.chatPeer = new ChatPeer(this, protocol);
106                 }
107             }
108
109#if UNITY
110#pragma warning disable 0162 // the library variant defines if we should use PUN's SocketUdp variant (at all)
111             if (PhotonPeer.NoSocket)
112             {
113#if !UNITY_EDITOR && (UNITY_PS3 || UNITY_ANDROID)
114                 UnityEngine.Debug.Log("Using class SocketUdpNativeDynamic");
115                 this.chatPeer.SocketImplementation = typeof(SocketUdpNativeDynamic);
116#elif !UNITY_EDITOR && UNITY_IPHONE
117                 UnityEngine.Debug.Log("Using class SocketUdpNativeStatic");
118                 this.chatPeer.SocketImplementation = typeof(SocketUdpNativeStatic);
119#elif !UNITY_EDITOR && (UNITY_WINRT)
120                 // this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
121#else
122                 Type udpSocket = Type.GetType("ExitGames.Client.Photon.SocketUdp, Assembly-CSharp");
123                 this.chatPeer.SocketImplementation = udpSocket;
124                 if (udpSocket == null)
125                 {
126                     UnityEngine.Debug.Log("ChatClient could not find a suitable C# socket class. The Photon3Unity3D.dll only supports native socket plugins.");
127                 }
128#endif
129                 if (this.chatPeer.SocketImplementation == null)
130                 {
131                     UnityEngine.Debug.Log("No socket implementation set for 'NoSocket' assembly. Please contact Exit Games.");
132                 }
133             }
134#pragma warning restore 0162
135#endif
136
137             this.chatPeer.TimePingInterval = 3000;
138             this.DisconnectedCause = ChatDisconnectCause.None;
139
140             this.CustomAuthenticationValues = authValues;
141             this.UserId = userId;
142             this.AppId = appId;
143             this.AppVersion = appVersion;
144             this.didAuthenticate = false;
145             this.msDeltaForServiceCalls = 100;
146
147
148             // clean all channels
149             this.PublicChannels.Clear();
150             this.PrivateChannels.Clear();
151
152             if (!address.Contains(":"))
153             {
154                 int port = 0;
155                 ProtocolToNameServerPort.TryGetValue(protocol, out port);
156                 address = string.Format("{0}:{1}", address, port);
157             }
158
159             bool isConnecting = this.chatPeer.Connect(address, "NameServer");
160             if (isConnecting)
161             {
162                 this.State = ChatState.ConnectingToNameServer;
163             }
164             return isConnecting;
165         }
File name: ChatBot.cs Copy
52         private void showOutput()
53         {
54             if (!(string.IsNullOrWhiteSpace(InputTxt.Text))) // Make sure the textbox isnt empty
55             {
56                 SoundPlayer Send = new SoundPlayer("SOUND1.wav"); // Send Sound Effect
57                 SoundPlayer Rcv = new SoundPlayer("SOUND2.wav"); // Recieve Sound Effect
58
59                 // Show the user message and play the sound
60                 addInMessage(InputTxt.Text);
61                 Send.Play();
62
63                 // Store the Bot's Output by giving it our input.
64                 string outtt = bot.getOutput(InputTxt.Text);
65
66                 if (outtt.Length == 0)
67                 {
68                     outtt = "I don't understand.";
69                 }
70
71                 //=========== Creates backup of chat from user and bot to the given location ============
72                 FileStream fs = new FileStream(@"chat.log", FileMode.Append, FileAccess.Write);
73                 if (fs.CanWrite)
74                 {
75                     byte[] write = System.Text.Encoding.ASCII.GetBytes(InputTxt.Text + Environment.NewLine + outtt + Environment.NewLine);
76                     fs.Write(write, 0, write.Length);
77                 }
78                 fs.Flush();
79                 fs.Close();
80                 //=======================================================================================
81
82                 // Make a Dynamic Timer to delay the bot's response to make it feel humanlike.
83                 var t = new Timer();
84
85                 // Time in milseconds - minimum delay of 1s plus 0.1s per character.
86                 t.Interval = 1000 + (outtt.Length * 100);
87
88                 // Show the "Bot is typing.." text
89                 txtTyping.Show();
90
91                 // disable the chat box white the bot is typing to prevent user spam.
92                 InputTxt.Enabled = false;
93
94                 t.Tick += (s, d) =>
95                 {
96                     // Once the timer ends
97
98                     InputTxt.Enabled = true; // Enable Chat box
99
100                     // Hide the "Bot is typing.." text
101                     txtTyping.Hide();
102
103                     // Show the bot message and play the sound
104                     addOutMessage(outtt);
105                     Rcv.Play();
106
107                     // Text to Speech if enabled
108                     if (textToSpeech)
109                     {
110                         reader.SpeakAsync(outtt);
111                     }
112
113                     InputTxt.Focus(); // Put the cursor back on the textbox
114                     t.Stop();
115                 };
116                 t.Start(); // Start Timer
117
118                 InputTxt.Text = ""; // Reset textbox
119             }
120         }

Interval 127 lượt xem

Gõ tìm kiếm nhanh...