Thread Safety, Application Design - Console App That Loops Through A Queue And Processes Each Record In A Datatable?
Jul 25, 2011
I have a Console app that loops through a queue and processes each record in a datatable. Each process is long and time-consuming (connecting to a remote website, downloading files, reading them and adding them to the database). I'm trying to implement threading for speed's sake but am having cross-threading issues. (The job takes 8 hours or so to run and the cross-threading doesn't start happening until a couple hours into the run.)I'm trying to figure out how to make my code thread safe. I don't update or rely on any non-local variables, and I don't need to return anything. I've tried locking which works but defeats the purpose of the multiple threads. What other things should I be looking for?
Lets say we have this code that runs in the constructor:
Dim initVectorBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(initVector) Dim saltValueBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(saltValue) Dim passPharse As String = GenerateKeyString(EncryptionKey) Dim password As Rfc2898DeriveBytes = New Rfc2898DeriveBytes(passPharse, saltValueBytes, passwordIterations) Dim keyBytes As Byte() = password.GetBytes(CInt(keySize / 8)) mSymmetricKey = New RijndaelManaged()
I have a multi-threaded application with several datasets that are read/written to from a couple threads. I have read that datasets can handle multiple readers and one writer. I have synclocks around all dataset writes and no synchronization around reads. I am experiencing random "Index was outside the bounds of the array." exceptions where a dataset item is in a conditional statement, for example:
is it ever possible to write locking-features(for threading) with the language itself (this question is purely academic, I know no one will ever do it even if its possible (not me))?
A) In Java, is it possible to write thread safety functions with java alone, but without using any of the provided classes/language elements/syntax which offer this feature?
B) In C#, is it possible to write thread safety functions with C# alone, but without using any of the provided classes/language elements/syntax which offer this feature?
C) In Vb, is it possible to write thread safety functions with Vb alone, but without using any of the provided classes/language elements/syntax which offer this feature?
How do run processes synchronously from a thread or backgroundworker thread? Is it even possible?We have program that allows the user to download several files from a remote server, compress them, and then email the files.It has several long running processes that must run in order. We want these to run on a separate thread so as not to make the form unresponsive. Does a way exist to do this? We attempted a rather clumsy way of approaching this problem by using background worker threads. When each thread is completed and returned back to RunWorkerCompleted, we start another background worker thread and repeat the the next process. It works somewhat but seems to take a lot of resources to run.
My application works with the sql database. It always connect to the databse using the same login and password written earlier in the application code.I just have a conncetion string with all that data inside.
I know that it is not the safiest way to do that. How to safely hold this thata inside of an application?
I'm receiving tons of statistics data that I need to insert into the db.I would like to implement some kind of Queue or FIFO class that keeps all the dataand when it reaches to a specific count (buffer), it will send that data to the SQL through bulk insert. This should be thread-safe.
It is my previous problem in vb6, its hard to multithread using vb6 so I migrate my codes to vb.Net.How can I multithread this two loops so that this process is running at the same time.Because when I start my second Loop, my first loop stop in executing. It will start again when my 2nd loop finished.
[code]...
I have 2 connected GSM Modem in usb port.That codes will send SMS in all contacts in my ListBox.
I have a console application I'm using to run scheduled jobs through windows scheduler. All the communication to/from the application is in email, event logging, database logs. Is there any way I can suppress the console window from coming up?
Am using vb.net windows application.Application containing one process with for and while loops.When i click on stop button then it should stop processing and it should losd gui.
I am getting this exception: Cross-thread operation not valid: Control 'TextBoxOutput' accessed from a thread other than the thread it was created on. in a VB 2008 Windows Forms application that I havent specifically made multi-threaded. I have create a sub called Out() like this:
Private Sub Out(ByVal inString As String) Me.TextBoxOutput.Text += (Me.TextBoxOutput.Text & inString & vbNewLine) Me.TextBoxOutput.SelectionStart = Me.TextBoxOutput.Text.Length Me.TextBoxOutput.ScrollToCaret() End Sub
and I call it from various events to log messages I am getting from my pbx, which I use a third party open source dll to access. The interesting thing to me is that if I run the deployed application (ie, not in the VS IDE) I do not get any exceptions, it's only from within the IDE.if I add the line: Control.CheckForIllegalCrossThreadCalls = False to the form's constructor, the exceptions stop, but a) this seems like a hacky way to get around the issue and b) the application seems to hang sometimes when I have it set this way.
I need to create a notification system for my application that will alert the user once new items have been sent to their queue, which is made of up database entries. The latter part of this question may need to be asked in the database forum, but I guess we'll figure that out First, since I haven't created anything like this before, I need some direction on what the best possible solution would be.The notification system should always be running and work independently of the main app. With this requirement, I thought a Windows Service would be best.
The notification itself will just be a quick form that alerts the user. I'm sure most of that will be fairly easy to create. The only issue I'm wondering about is how to constantly check the database and determine a new record has been inserted.Would a windows service have a timer or something that allows me to constantly check?If it does, how would I determine a new record has been inserted?
I am currently working on an application, where I am using a console application, that will set up the application prior to the main form is run. This is no problem I've got that all working perfectly, the only problem I have is that the console is showing while the application is running, I was wondering whether anyone knows any way in which I would be able to hide the console before it gets shown to the user.
How do I get the console from closing immediatley upon opening in a Console Application program? I have all of the code written but when I run the program it pops up the console window and then immediatley exits so I am unable to read what is in the window to see if my program is operating correctly. This is the first time I've ever used a console window so I don't know where in the code I would need to put "whatever it is" I might need to put to keep the window open until closed by the user.
It sounds confusing but it's not really. What I need is basically a way to emulate the console style text, without using a console. What I'm really doing is trying to do a matrix effect on my form background, by drawing symbols and moving them, alternating their colors (see this video for what I mean).
Is there a way to do this effectively with a timer and a draw event, with the timer calling the draw event and changing the intervals?
I have a thread in an application which calls a sub routine Main(). The Main sub routine in turn call several sub routines/functions from with the same module,several different classes in the same application. Also some sub routines/functions call routines from a class library. Now say the routine/function in class library goes into a infinite loop and never returns. I would like my thread in the application to raise a event and display message to the users about the infinite loop. I am giving some sample code for the application.
My routine to check for updates is run as a separate process. Exiting the application is required to update, so a dialog asks the user, when an update is found, if they want to exit now. f they do, the code (from the update thread) calls Application.Exit().However, if the FormClosed event of any form that needs to be closed needs to access its controls, an invalid cross-thread operation is detected (which sounds pretty logical).
the purpose of the program is to display the monthly payments on the loan.My homework is to use do while loops instead of for loop.Here is the code for the for loop.
Option Explicit On Option Strict On Option Infer Off
[code].....
Now I'm having some trouble displaying the output using the do while loop, and I'm pretty sure it's a loop problem on my code. However, I cannot seemed to find out what's wrong. I looked at the examples of do while loop in my textbook, but I couldn't find anything useful to my problems of my program.This is the output for the do while loop.
Here's the do while loop code
Option Explicit On Option Strict On Option Infer Off
I'm using a MySQL connector in VB .Net to execute a batch of SQL inserts. This is typically on the order of 5k statements and takes around 30 minutes to process. Unfortunately, when this process is running and I use a different application on the system, upon returning to the .net app it hangs and shows "not responding". In fact, as soon as I click anywhere else in the application (move to a different tab, for example) everything locks up.
Dim transaction As MySqlTransaction = sqlConnection.BeginTransaction() For Each sqlCmd In (sqlCmdsCollection) sqlCommand = New MySqlCommand(sqlCmd, sqlConnection)
I have rently deployed a VB windows application. It uses ADO typed datasets and datagrids.
On a couple of machine, if the application is left opened for a while (about more than 30 minutes), it gives no response. In order to restart it, I need to end the process vie the Task manager.
How would I even begin to troubleshoot why it is "hanging up"?
I am trying to learn by creating a small application to help my son learn math. It works but I know there are better ways of accomplishing what I need.
For example:
'Declare variables Dim num1 As Double = CDbl(frmMath.txtNum1.Text) Dim num2 As Double = CDbl(frmMath.txtNum2.Text) Dim answer1 As Double = CDbl(frmMath.txtAnswer.Text)
[CODE]...
I imagine I would need something like a do while loop?
I am trying to create an application that will identify a process using over 50% of the CPU and set its affinity to run only on core 0. How should I go about creating this? P.S. I am trying to create this application because my PC has been creating this really anoying screaching sound when a process randomly uses over 50% of my CPU. (I have a dual-core, AMD sadly.)
Is it possible to edit/get data from a DataTable from another thread? On one form, I'm declaring a DataTable and loading it with some data. On the same form, I have a sub wich does some updates to the DataTable.
Now, I want to call that sub from another thread, but it seems like an impossible task... When I for example do a 'for each' in the sub wich updates the DataTable, it doesn't actually refer to the DataTable. All the rows and columns are not there.
I've been reading about some cross-threading and found some example where the objects invoke-property is used. But the DataTable does not have a invoke-property. So, how is it possible to do what I'm trying to do? I've been searching the forum/web for a while now, but maybe someone here can point me in the right direction?
We are currently developing a WPF/Entity-Framework based application.One of our requirements was to allow the user option to select which environment(testing, training, or production) they will connect to when logging in.Each connection option points to its own database.In order to do this we are creating new EF contexts in the following way:[code]We have made sure that all new contexts are being disposed of once its job is completed.The problem is this: when the users are using the application we are seeing hundreds of SQL Server processes in SQL Server's activity monitor. Some individual users have upwards of 30+ processes associated when using the app. Once the user shuts down the app the associated processes all disappear - but while the app is running these processes seem to stick around.
I am a new member here and a new user of VB.Net.So, I would like to know how to make an application that can control the processes and the services in a remote machine.
I am trying to make an application which will list all processes in a string when it starts. After it has listed them all I enable my timer, and in the timer there gets checked if the process is in the process list (string), and if it isn't it will add it to my listbox. The only problem is, it's not working, it's never adding an item.
vb.net
Public Class Form1 Dim AllProcesses As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'The first check For Each p In System.Diagnostics.Process.GetProcesses() If AllProcesses = "" Then AllProcesses = p.ProcessName Else AllProcesses += "|" + p.ProcessName End