Multithreading - Threading Function That Takes Variables And Returns A Datatable
Mar 7, 2012
I've been looking at threading to make my webapplications more responsive. I've found out how to thread a sub that takes no variables and doesn't return anything, but I can't find out how to achieve this for a function that takes variables and returns something. here is an example
An in-line table valued function in SSMS takes about 6 seconds to return 11088 records. The same function in VB .Net 4.0 using TableAdapters.InputTableAdapter.GetData (Created with data set designer) takes about 15 minutes complete.Both are executed from the same workstation.Why does this discrepancy exist?
Question 1: What is the difference between "Background Worker" and "Worker Pool" as indicated within the MSDN samples provided.
Question 2: I noticed while using, AddressOf _Function_, variables cannot be passed; what would be an efficient solution to this?
Question 3: While using multithreading is it required to invoke before setting variables, or only form properties?
Question 4: While using System.Net.Sockets is it safe/efficient to use Application.DoEvents while waiting for new data; or would be using a Do While loop be fine without DoEvents since the action would be multithreaded? Note: there can be up to 2000-3000 sockets in use at a time.
I have some functions in a web application that do a lot of calculations and as a result have high CPU usage which affects the rest of the application when other users are accessing it. I have tried background-worker to no avail , the only thing that seems to work in using another thread and setting the priority to low, can the UI be updated from a worker thread? specifically I am trying to bind a grid to a dataset processed in the worker thread
I have a console application that is built in VB.Net. Now I have a timer in that application. All I want to do is at a particyualr time i will call another exe (which is built in VB 6.0) and again get the control back to this console application. Now what is happening is that I am being able to call the second exe from the console application, but then the control is not returning back to the same console application.
I am working on a simple vb project to read data from a PC serial port and write that data to a file.The data is ascii sent in Hex format. I used MySerialPort.ReadChar() to read data and MyStreamWriter.Write(MySerialPort.ReadChar()) to write it to a file.
I copied my code below, sorry about the format.The trouble is: MySerialPort.ReadChar() acts the same as MySerialPort.ReadByte() , both takes the Hex data input and returns data in decimal format.I tried to use Convert.ToChar(MySerialPort.ReadChar()) to covert decimal to char, but it's too slow.I tried decimal.ToChar(MySerialPort.ReadChar()), but VB doesn't recognize decimal.ToChar, even after I installed .NET4.
Did I do something wrong? how to make MySerialPort.ReadChar() to read Hex data and return char?
I'm new to coding and i need to make a program that takes 3 percentages(numbers) and returns an average of the grades in letter format(A,B,C). This is what I have so far:[code]......
To have a function that takes the average (which is calculated by a different function) say for example the average is 6, now the function is to take the number 6 and get the variance from six to another number lets say its 12 so this will return a calculation of 50% variance. now here comes the issue, i have it calculating the variance how ever lets say that there is a score that is 0, how can i make it calculate the variance without taking count for that 0? i guess you can say i need it to "skip" if its a 0.
So I am currently attempting to wrap my head around create multi-threaded programs and I am currently running into an issue when using a Shared variable across multiple threads.The program is structured as follows: Public Shared IsActive as Boolean
Main Thread = GUISets the Value of IsActive through a Button ControlTwo Worker ThreadsBoth threads are while loops that read the IsActive Boolean Ex:While IsActive = True Do Work End WhileHowever when I change the value of IsActive from the Main Thread it causes the worker threads to stop (ThreadState = 16).
I have been reading that I have to synchronize/lock shared resources and have tried SyncLock and Monitor methods without success (it is entirely possible I am not using the above correctly, so If someone could provide proper examples for the above situation using the mentioned methods please share them).
Is there a way in vb.net to create a sub/function that will take as an argument some kind of pointer to another function, and allow this new sub/function to execute the passed function? What I have are 10-12 xml-rpc functions I am calling against a remote server. Each of these functions has different argument lists (one takes 1 string, another might take 3 strings and one int, etc). All of them return an object.
Actually, I am trying to find out whether the partno is existing in the database table or not and it takes long time in count = checkCommand.ExecuteReader statement
Public Function CheckProductNo(ByVal Partno As String) As Boolean Dim count As SqlDataReader Dim valid As Boolean = False Using connection As New SqlConnection
what exactly is the type of the second argument of CType
CType(testobject, Control)
what exactly is Control? how can Control be used as though it is an expression?i nid to know this because i'm trying to build a function that takes the exact parameters of CType, let's call it CType2public function CType2 (byref object as Object, byval thetype as Type) as Object problem is when i do this: CType2(testobject, Control) they give me "Control is a type and cannot be used as an expression".
I'm currently invoking a function that takes ByRef parameters using Control.Invoke (which I notice specifies the Object parameter array to be ByVal) but the array of parameters I give it isn't updated by the function. Is this possible with VB.Net 2003 or must there be some error in my code?
I'm a beginner and doing a review for my final...the question is-Write a Function procedure that takes an array of Strings, sorts it using Shell sort and returns the sorted array. I do not get shell sort at all.
This is probably a stupid question, but how do you make a function which takes a number then does an operation to it again and again until it gets a vlue which it already has seen, when it returns all of its values? I have this function:
Private Function fractal(d as string) As double Fractal = Val(D) * (Val(D) - 1) Fractal = FormatNumber (Fractal, 2)
The following VB line, where _DSversionInfo is a DataSet, returns no rows: _DSversionInfo.Tables("VersionInfo").Select("FileID=88") But inspection shows that the table contains rows with FileID's of 92, 93, 94, 90, 88, 89, 215, 216. The table columns are all of type string.
Further investigation showed that using the ID of 88, 215 and 216 will only return rows if the number is quoted. i.e. _DSversionInfo.Tables("VersionInfo").Select("FileID='88'") All other rows work regardless of whether the number is quoted or not. I understand that the numbers should be quoted just not why some work and others don't?
Public Sub Submit( ByVal reasonId As Integer, ByVal email As String, ByVal message As String ) '[Argument validation code here] EmailController.sendMail(reasonId, email, message) End Sub
I want to spin this off in a new thread so Submit() returns right after creating and start the thread.In C#, I could do something like this:new Thread(() => { EmailController.sendMail(reasonId, email, message)}).Start();
I have to cut down the amount of code in my blackjack program so im trying to use a function however the function always returns a value of 0 I have tried putting in "return cardvalue" but it still comes out as 0 I dont know where I went wrong or if the code im using can even be used as a function.
Function Values(ByVal deal() As Integer, ByVal counter As Integer, ByVal cardvalue As Integer) As Integer If deal(counter) = 1 Or deal(counter) = 2 Or deal(counter) = 3 Or deal(counter) = 4 Then
I wrote a vb program that would prompt the user to enter a number and then enter the exponent value they wanted the number raised to. When they clicked button 3 it did the calculation. everything worked perfectly.
Now I need to change the program. I must create a function in a module and then call that function from button3 click event. I have tried several different ways and even though it seems to "work", it keeps returning an incorrect value![code]...
I have to create dinamcly a Table ( not a DataTable) and I need to write the Functions in other class... so I need to create a function that Returns a Table to make possible I just atribuite the Table to my <asp:Table> control.
I've been trying to get this part of my code to work but it hasn't done anything. I'm trying to create a function that sends an email everyday at a specific time. I thought threading.timer would work but i haven't figured it out yet. I don't get errors when its executed but it also does nothing. If someone could tell me whats going on with this piece of code,
I need top create a function that gets the next integer in the sequence of 1 to 60. Each time the function is called, I need it to increment from what the last value was and return the next number as the result. It also cannot return the same integer in 2 consecutive calls. When the count gets to 60, the sequence needs to reset back to 1. I would like to function to have no parameters.
I have created a function that does this using the cache to store the last value that was returned, but I am worried that with concurrent calls to the function that it might not work as I expect and 2 calls could get the same integer.
Is cache blocking the correct method to use in this instance or is there something other method I am not thinking about?
Also, stuck using .Net 3.5 and this is a web application.
I just wrote this function based on using SyncLock. Any obvious problems with it that I don't see? I am using the Cache to save the last value that was returned.
Private Shared Function GetNextNumber() As Integer Dim o As Integer Dim r As Integer
I have a function that returns a bitmap meant to be used as background in a panel, and occasionally I'd have to call it to create a new background based on parameters
How can I call individual parts of this function? I would like to call return Gallons and decPaintCostperRoom as individual entities with a single function.