473,811 Members | 3,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread does not sleep in Console application

375 Contributor
Hello
I have written the following in console application.
My problem is I want the application running in the back.
and it should check every thirty minutes and update thedatabase

the problem is that the threading does not work
and to make the application run every thirty minutes am i suppose to create a windows service.

Please let me know
Thanks


Expand|Select|Wrap|Line Numbers
  1.  Sub Main()
  2.         Dim Th As New Thread(AddressOf CheckTimeDifference)
  3.  
  4.         Th.Start()
  5.  
  6.  
  7.     End Sub
  8.     Private Sub CheckTimeDifference()
  9.  
  10.         Try
  11.  
  12.             MyCon = New SqlConnection("server=ccccccc;uid=;pwd=;database=ee")
  13.             MyCon.Open()
  14.  
  15.             chkTime = Now
  16.             StrSql1 = "Select REGISTRATIONNO,MAX(GPS_DATETIME) FROM GPSDATA_HISTORY group by REGISTRATIONNO"
  17.             MyCmd = New SqlCommand(StrSql1, MyCon)
  18.  
  19.             Da = New SqlDataAdapter(StrSql1, MyCon)
  20.             Ds = New DataSet()
  21.             Da.Fill(Ds, "ChkTable")
  22.  
  23.             RowCount = (Ds.Tables("ChkTable").Rows.Count)
  24.             For I = 0 To RowCount - 1
  25.  
  26.                 RegNo = (Ds.Tables("chktable").Rows(I)(0))
  27.                 dataTime = (Ds.Tables("chktable").Rows(I)(1))
  28.  
  29.                 TimeDiff = DateDiff(DateInterval.Minute, dataTime, chkTime)
  30.                 If TimeDiff > 30 Then
  31.                     StrSql1 = "Update gpsdata set speed=0 ,ignition=0 where registrationno='"
  32.                     StrSql2 = RegNo & "'"
  33.                     StrSql = StrSql1 + StrSql2
  34.                     MyCmd1 = New SqlCommand(StrSql, MyCon)
  35.                     MyCmd1.ExecuteNonQuery()
  36.                     Console.WriteLine("Speed details, Ignition Details has been changed in GPS DATA")
  37.                     StrSql3 = "Update gpsdata_history set speed=0 ,ignition=0 where registrationno='"
  38.                     StrSql4 = RegNo & "' and gps_datetime='" & dataTime & "'"
  39.                     StrSql5 = StrSql3 + StrSql4
  40.                     MyCmd2 = New SqlCommand(StrSql5, MyCon)
  41.                     MyCmd2.ExecuteNonQuery()
  42.                     Console.WriteLine("Speed details, IgnitionDetails has been changed in GPSDATAHISTORY")
  43.                 End If
  44.  
  45.             Next
  46.  
  47.         Catch e As Exception
  48.  
  49.             Console.WriteLine(e.ToString)
  50.             Thread.Sleep(60000)
  51.  
  52.         End Try
  53.  
  54.     End Sub
  55. End Module
Jul 23 '07 #1
3 1850
cmrhema
375 Contributor
Hello
I have written the following in console application.
My problem is I want the application running in the back.
and it should check every thirty minutes and update thedatabase

the problem is that the threading does not work
and to make the application run every thirty minutes am i suppose to create a windows service.

Please let me know
Thanks


Expand|Select|Wrap|Line Numbers
  1.  Sub Main()
  2.         Dim Th As New Thread(AddressOf CheckTimeDifference)
  3.  
  4.         Th.Start()
  5.  
  6.  
  7.     End Sub
  8.     Private Sub CheckTimeDifference()
  9.  
  10.         Try
  11.  
  12.             MyCon = New SqlConnection("server=ccccccc;uid=;pwd=;database=ee")
  13.             MyCon.Open()
  14.  
  15.             chkTime = Now
  16.             StrSql1 = "Select REGISTRATIONNO,MAX(GPS_DATETIME) FROM GPSDATA_HISTORY group by REGISTRATIONNO"
  17.             MyCmd = New SqlCommand(StrSql1, MyCon)
  18.  
  19.             Da = New SqlDataAdapter(StrSql1, MyCon)
  20.             Ds = New DataSet()
  21.             Da.Fill(Ds, "ChkTable")
  22.  
  23.             RowCount = (Ds.Tables("ChkTable").Rows.Count)
  24.             For I = 0 To RowCount - 1
  25.  
  26.                 RegNo = (Ds.Tables("chktable").Rows(I)(0))
  27.                 dataTime = (Ds.Tables("chktable").Rows(I)(1))
  28.  
  29.                 TimeDiff = DateDiff(DateInterval.Minute, dataTime, chkTime)
  30.                 If TimeDiff > 30 Then
  31.                     StrSql1 = "Update gpsdata set speed=0 ,ignition=0 where registrationno='"
  32.                     StrSql2 = RegNo & "'"
  33.                     StrSql = StrSql1 + StrSql2
  34.                     MyCmd1 = New SqlCommand(StrSql, MyCon)
  35.                     MyCmd1.ExecuteNonQuery()
  36.                     Console.WriteLine("Speed details, Ignition Details has been changed in GPS DATA")
  37.                     StrSql3 = "Update gpsdata_history set speed=0 ,ignition=0 where registrationno='"
  38.                     StrSql4 = RegNo & "' and gps_datetime='" & dataTime & "'"
  39.                     StrSql5 = StrSql3 + StrSql4
  40.                     MyCmd2 = New SqlCommand(StrSql5, MyCon)
  41.                     MyCmd2.ExecuteNonQuery()
  42.                     Console.WriteLine("Speed details, IgnitionDetails has been changed in GPSDATAHISTORY")
  43.                 End If
  44.  
  45.             Next
  46.  
  47.         Catch e As Exception
  48.  
  49.             Console.WriteLine(e.ToString)
  50.             Thread.Sleep(60000)
  51.  
  52.         End Try
  53.  
  54.     End Sub
  55. End Module

Problem Resolved
Put a dowhile loop
and put the thread sleep after end try
Jul 23 '07 #2
cmrhema
375 Contributor
Problem Resolved
Put a dowhile loop
and put the thread sleep after end try
I have created a windows installer using VB.net 2005
(as per msdn link given below)
http://msdn2.microsoft .com/en-us/library/zt39148a(VS.80) .aspx

Now I need to include the above said application inside the windows service.
How to do?
Jul 23 '07 #3
cmrhema
375 Contributor
I have created a windows installer using VB.net 2005
(as per msdn link given below)
http://msdn2.microsoft .com/en-us/library/zt39148a(VS.80) .aspx

Now I need to include the above said application inside the windows service.
How to do?
Problem Solved
Installed it in windows service
Jul 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2890
by: Keyee Hsu | last post by:
Hi, I have a C# app that creates an AppDomain, enters it, and spawns an asyn thread to do some work and then block itself. Upon the completion of the work, the async thread supposedly terminates, then the original thread unblocks, unloads the AppDomain, and starts the whole process all over again. I get the System.AppDomainUnloadedException saying that the AppDomain from which the async thread resides has been unloaded. Now, if I were...
4
1981
by: Leonardo Hyppolito | last post by:
Hello, I am trying to write a multithread program that simulates producers and consumers. My program can have many producers and many consumers (each in a separate thread). It has a storage place (buffer) with "n" capacity. The user provides these parameters on startup. The buffer works with a circular queue. It's a console application. My implementation is working with Semaphores to synchornize everything. I think it's synchornized...
6
2297
by: Daniel | last post by:
i have an array that i want all threads to be able to READ from concurrently, however, at times i want to UPDATE the array. at which point i want all threads that use it to block when they try to read from the array. currently i do this by wrapping ALL READ AND WRITE access to the array in a lock("foobar"){} this prevernts threads from reading from the array while it is being written to however it ALSO keeps more then one thread from...
0
1077
by: lukasz | last post by:
Hi, could somebody analyze a class and suggest what to do to avoid hanging the class (thread) when the application calling it exits? (Other than using background threads). This class is something similar to a splash screen. Thanks using System; using System.Drawing; using System.Windows.Forms; using System.Threading;
3
6178
by: Raj Wall | last post by:
Hi, I have an application that uses a number of sub-threads. What is the best way to do some processing in each thread when the main application is shut down? Is the ThreadAbortException thrown automatically for each thread? Or is there some other event or exception automatically thrown that the thread can "grab" as it is shut down?
8
1702
by: Carl Heller | last post by:
If I'm creating a class to do some work that I want threaded out, where's the best location to call ThreadStart? Or does it depend on the nature of the work? a. Call it outside the class, giving it the starting method of the class? b. Have the class create the thread itself? ie: x = new WorkerClass(); ioThread = new Thread(new ThreadStart(x.StartWork));
0
1328
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I have a windows application that does not stop running whenever the application exits. Could someone fill me in on what I am doing wrong? Here is the relevant code: ================================= Private m_thTCP As Thread Private m_listener As TcpListener
9
6996
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table population. Whenever I call the thread, I pass it a structure containing the table and a few other parameters. The table goes in as a reference, but the other items are passed normally.
3
3185
by: yeye.yang | last post by:
hey everybody Does everybody can help me or give me some advise for the cross thread exception catch Here is what I want to do: I have 2 classes "Scenario" and "Step", which have a System.Thread.Timer for each to control their timeout gestion, in my "main program", I start the "Scenario" and "Step", and I do something between "StepStart" and "StepStop", when "Scenario" or "Step" timeout expired, they raise an "exception", then my "main...
0
9726
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10395
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10130
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7667
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6887
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.