|
It's when I attempt to update the DB when the exception occurs. All I want is for the DataSet to update the DB without supplying a PK, and not through an exception because one wasn't supplied.
"you can't forget something you never knew..." M. Du Toit
"Watching Migthy Joe Young made me hate my life..................................I want a gorilla!" A. Havemann
|
|
|
|
|
evilnoodle wrote: the first problem I get is that the Primary Key for the new record is wrong,
why do you say this?
Shreekar
|
|
|
|
|
Because the DataTable is filled with only one record, when adding a new one, I basically clear the data from the DataTable to enter the new record, but the communication between the actual DB and my application is lacking because it the identity that's automatically entered into the PK column is one bigger than the last record the DataTable was filled with, and from there on, every new record is given a PK value of 1 more than the last one.
Say the next entry in my DB requires a ID of 2110, but my DataTable is loaded with a record ID:1152, clicking my new record button which does a BindingSource.AddNew() adds a record with ID 1153.
"you can't forget something you never knew..." M. Du Toit
"Watching Migthy Joe Young made me hate my life..................................I want a gorilla!" A. Havemann
|
|
|
|
|
Hi,
I am working on a project that uses a VB.NET application for sending e-mails. This application works as a scheduler and is scheduled to start after every 1 min. It works as follows:
1. It picks up the projects that are scheduled to run(send mails).
2. It picks up the contacts to which the mail needs to be sent.
3. It sends the mail.
Now I have used threading so that each project picked up in the 1st step is executed as a different thread. Now the problem is that when the scheduler starts again after 1 min, the projects picked by this instance have to wait for completion of all the threads belonging to the previous instance. I want these new threads to also start concurrently with the previous threads that are already running.
Any suggestions on this will be highly appretiated.
regards,
Sandeep
|
|
|
|
|
Perhaps if you can't finish the task in a minute, you need to run it less often ? I mean, you can't get more speed out of having all those threads, the older ones will just wait longer, for the ones that have been started.
You can create all the threads you want, that's not an issue. But, I wonder how many is practical.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi,
Thanks for the reply but why it is happening that threads(say 4 project threads) belonging to the one instance of the scheduler(our application) and other threads belonging to separate instance(2nd instance that will be created after 1 minute), what exactly prevents threads from 2nd instance to start.Is there any background and foreground threads kind of issue.
Regards
Sandeep
|
|
|
|
|
Nothing, I don't see how that is possible. What makes you think it's the case ? Why is it running twice ? How many instances will be running, over time ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Let me explain:
Suppose the scheduler runs for the first time and it picks 5 projects(5 threads). Supposing each project has 1000 contacts to whom the mail needs to be sent.
Now the scheduler is scheduled to run after every 1 min. So after 1 min the second instance of the scheduler starts and it picks 5 more projects(5 more threads). Now these new threads keep on waiting till the mails are sent to the contacts of first 5000 contacts. It is only after these mails are sent the threads in the second instance start.
Our system sends about 600 mails in a minute. Even if the mails are not sent for the previous instance the threads in the second instance should atleast start.
|
|
|
|
|
OK, it sounds like the mail class can only send one mail at a time ( which seems possible ). So, as I said, the question is, why does it have to run every minute ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
We need to run it quite frequently because the projects added by our clients should be serviced as soon as they are added.
Even if we increase the time of executing the scheduler it may solve the problem temporarily. But my point is why should the threads wait, I mean this should not happen (conceptually atleast!).
|
|
|
|
|
Sandeep_S wrote: We need to run it quite frequently because the projects added by our clients should be serviced as soon as they are added.
If they wait more than 60 seconds, the world will end ?
Really, you should have a single queue, which gets added to, not several queues. It seems to me that the answer is almost certainly that your method of sending emails is written this way, so a single queue is formed, even if you didn't impliment your app this way.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
This is the way we have implemented the app:
Dim objThreadList As ArrayList
Sub Main()
Schedule()
End Sub
Public Sub Schedule()
For Counter = 0 To dsProject.Tables(0).Rows.Count - 1 ''Loop runs for each project
CallThread(dsProject.Tables(0).Rows(Counter), Counter)
Next
End Sub
Public Sub CallThread(ByVal drProject As DataRow, ByVal counter As Integer)
objThreadList.Add(New Thread(AddressOf ThreadProcess))
drThread = drProject
objThreadList(counter).Start()
End Sub
Public Sub ThreadProcess()
Dim objClsProject As New clsProjectThread
objClsProject.ActualProcess()
End Sub
Public Sub ActualProcess()
'Code for sending mail
End Sub
|
|
|
|
|
I don't see how that proves anything. Like I said, it seems to me like the code for sending emails is forming a queue of mails to send. The mails from the first thread, get sent first.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Sandeep_S wrote: the projects picked by this instance have to wait for completion of all the threads belonging to the previous instance
Why?
---
Year happy = new Year(2007);
|
|
|
|
|
Guffa wrote:
Why?
That's what I can't figure out.
|
|
|
|
|
Don't you even know why you are asking the question?
How have you come to the conclusion that the first thread has to finish before starting the next?
---
Year happy = new Year(2007);
|
|
|
|
|
Because I have monitored the working of the scheduler.
The thing I am unable to understand is why does it require the threads of first instance to be completed before starting the threads of the second instance (Because this is what is happening).
|
|
|
|
|
The threads work independently, unless you prevent them to. If the threads are waiting for each other, it has nothing to do with the threading. It's either a problem with performance as you are trying to do too much at the same time, or a limitation in some resource that the threads are using, like for instance the SMTP server.
---
Year happy = new Year(2007);
|
|
|
|
|
So can I safely assume that my code is fine and I have to find out the problem elsewhere may be in the server or some other resource.
|
|
|
|
|
Do you mean to say that the threads of the second instance are not even started? OR that the threads of the second instance are started but no mails are sent? If second case is true, then the bottleneck most probably is the SMTP server. Did you check the outbox of the SMTP server if possible?
Alternatively, you can use a timestamp to indicate which users/projects have been sent an email in the last 15 mins or so, and not re send the emails to them. This way, at least 10 instances of your application (1 per minute for 10 mins) will not attempt to send 1000s of emails. IMHO, the user will be very annoyed if he really receives a mail per minute reminding him the same thing!
Shreekar
|
|
|
|
|
Yes, the threads of second instance are not even started.
|
|
|
|
|
How are you starting the application after each minute? The problem might be there.
Shreekar
|
|
|
|
|
I use Windows Scheduling. ie. I have registered the application with Windows Scheduled tasks. It automatically executes after 1 minute.
|
|
|
|
|
OK
Then you need to eliminate the reasons. Write another app that does something for more than a minute - like counting from 1 to 1000000, then enumerating files in a folder , writing to a log file etc.
Then schedule this new app similarly for each minute and study whether this displays the same behaviour, if it does, the problem is the scheduler, and I dont know what can be done about it.
If not, the problem is the mail sending code/SMTP.
Shreekar
|
|
|
|
|
Fine, I will figure out this. But most probably I think the problem is with the Windows Scheduler. I think we should make this a windows service instead of scheduling it at intervals. The windows service would run continously without stopping.
What do you say?
|
|
|
|