|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Class used by multiple threads to write to Tableclass will be called by multiple threads. I'm hoping the table can stay in memory between calls and all the call by the thread will have to do is pass some data to be added to the table. Kinda like this class I have to write to a log file. Public Class MyStringLogger Private Shared m_loglock As New Object Public Shared Sub Write(ByVal fileName As String, ByVal strToWrite As String) SyncLock (m_loglock) Try Dim sw As New System.io.StreamWriter(fileName, True) sw.WriteLine(strToWrite) sw.Close() Catch End Try End SyncLock End Sub End Class Any idea how I'd do this? cj,
Are you sure that you don't need the queue class which is very standard for this? http://msdn2.microsoft.com/en-us/library/ms287330.aspx I hope this helps, Cor Show quoteHide quote "cj" <cj@nospam.nospam> schreef in bericht news:OenEEPunGHA.4892@TK2MSFTNGP03.phx.gbl... >I want to make a class that will write data to a in memory table. This >class will be called by multiple threads. I'm hoping the table can stay in >memory between calls and all the call by the thread will have to do is pass >some data to be added to the table. Kinda like this class I have to write >to a log file. > > Public Class MyStringLogger > Private Shared m_loglock As New Object > > Public Shared Sub Write(ByVal fileName As String, ByVal strToWrite As > String) > SyncLock (m_loglock) > Try > Dim sw As New System.io.StreamWriter(fileName, True) > sw.WriteLine(strToWrite) > sw.Close() > Catch > End Try > End SyncLock > End Sub > End Class > > Any idea how I'd do this? Hi Cj,
It seems Cor Ligthert [MVP] provided an incorrect URL for queue class, I think he is referring the URL below: "Queue Class" http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/ frlrfsystemcollectionsqueueclasstopic.asp There are several container classes in .Net may fit your need, such as ArrayList, Hashtable, Queue etc..., they all exist under System.Collections namespace. They all have different usages, you may refer to MSDN for their difference and choose the suitable for using as memory container table. Hope this helps! Best regards, Jeffrey Tan Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Jeffrey,
Thank you, I did not copy it this was from a previous answer, mine was http://msdn2.microsoft.com/en-us/library/system.collections.queue.aspx A little bit shorter than your URL. By the way, the queue class (FIFO) is extremely sufficient with multi threading. Cor ""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> schreef in bericht Show quoteHide quote news:IIsQlK1nGHA.4612@TK2MSFTNGXA01.phx.gbl... > Hi Cj, > > It seems Cor Ligthert [MVP] provided an incorrect URL for queue class, I > think he is referring the URL below: > "Queue Class" > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/ > frlrfsystemcollectionsqueueclasstopic.asp > > There are several container classes in .Net may fit your need, such as > ArrayList, Hashtable, Queue etc..., they all exist under > System.Collections > namespace. They all have different usages, you may refer to MSDN for their > difference and choose the suitable for using as memory container table. > > Hope this helps! > > Best regards, > Jeffrey Tan > Microsoft Online Community Support > ================================================== > When responding to posts, please "Reply to Group" via your newsreader so > that others may learn and benefit from your issue. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no > rights. > I'm don't think that's what I'm looking for. My program creates threads
to handle IP connections made to it. I've seen up to 66 concurrent threads running to date. But usually it's around 3 or 4. For accountability purposes each thread uses the MyStringLogger class I posted in my first message to write it's results to a log file. SyncLock is used to ensure only one thread is writing data at a time. Now I'm trying to write into this program another type of log. Each thread will be required to write two fields to an in memory db table. Why--Each thread receives a request from a IP client then calculates and sends a response to it. Part of the calculations involve other machines and if the network is down the threads can't calculate the response so they return an error code. In the future if the network is down I want the program to search the new in memory db table for the last time that question was asked by an ip client and return the same answer as it will most likely still be correct. Perhaps hourly a maintenance routine will be run to remove entries from this in memory db table older than X hours or minutes or whatever is determined to be appropriate. Any suggestions? Cor Ligthert [MVP] wrote: Show quoteHide quote > Jeffrey, > > Thank you, I did not copy it this was from a previous answer, mine was > > http://msdn2.microsoft.com/en-us/library/system.collections.queue.aspx > > A little bit shorter than your URL. > > By the way, the queue class (FIFO) is extremely sufficient with multi > threading. > > Cor > > ""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> schreef in bericht > news:IIsQlK1nGHA.4612@TK2MSFTNGXA01.phx.gbl... >> Hi Cj, >> >> It seems Cor Ligthert [MVP] provided an incorrect URL for queue class, I >> think he is referring the URL below: >> "Queue Class" >> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/ >> frlrfsystemcollectionsqueueclasstopic.asp >> >> There are several container classes in .Net may fit your need, such as >> ArrayList, Hashtable, Queue etc..., they all exist under >> System.Collections >> namespace. They all have different usages, you may refer to MSDN for their >> difference and choose the suitable for using as memory container table. >> >> Hope this helps! >> >> Best regards, >> Jeffrey Tan >> Microsoft Online Community Support >> ================================================== >> When responding to posts, please "Reply to Group" via your newsreader so >> that others may learn and benefit from your issue. >> ================================================== >> This posting is provided "AS IS" with no warranties, and confers no >> rights. >> > > cj,
Reading it, and trying to understand it, would I go to the sorted list (with a good created key) or the hashtable with the same as already stated by Jeffrey, Cor Show quoteHide quote "cj" <cj@nospam.nospam> schreef in bericht news:uQJyWnDoGHA.776@TK2MSFTNGP04.phx.gbl... > I'm don't think that's what I'm looking for. My program creates threads > to handle IP connections made to it. I've seen up to 66 concurrent > threads running to date. But usually it's around 3 or 4. For > accountability purposes each thread uses the MyStringLogger class I posted > in my first message to write it's results to a log file. SyncLock is used > to ensure only one thread is writing data at a time. > > Now I'm trying to write into this program another type of log. Each > thread will be required to write two fields to an in memory db table. > Why--Each thread receives a request from a IP client then calculates and > sends a response to it. Part of the calculations involve other machines > and if the network is down the threads can't calculate the response so > they return an error code. In the future if the network is down I want > the program to search the new in memory db table for the last time that > question was asked by an ip client and return the same answer as it will > most likely still be correct. > > Perhaps hourly a maintenance routine will be run to remove entries from > this in memory db table older than X hours or minutes or whatever is > determined to be appropriate. > > Any suggestions? > > > Cor Ligthert [MVP] wrote: >> Jeffrey, >> >> Thank you, I did not copy it this was from a previous answer, mine was >> >> http://msdn2.microsoft.com/en-us/library/system.collections.queue.aspx >> >> A little bit shorter than your URL. >> >> By the way, the queue class (FIFO) is extremely sufficient with multi >> threading. >> >> Cor >> >> ""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> schreef in bericht >> news:IIsQlK1nGHA.4612@TK2MSFTNGXA01.phx.gbl... >>> Hi Cj, >>> >>> It seems Cor Ligthert [MVP] provided an incorrect URL for queue class, I >>> think he is referring the URL below: >>> "Queue Class" >>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/ >>> frlrfsystemcollectionsqueueclasstopic.asp >>> >>> There are several container classes in .Net may fit your need, such as >>> ArrayList, Hashtable, Queue etc..., they all exist under >>> System.Collections >>> namespace. They all have different usages, you may refer to MSDN for >>> their >>> difference and choose the suitable for using as memory container table. >>> >>> Hope this helps! >>> >>> Best regards, >>> Jeffrey Tan >>> Microsoft Online Community Support >>> ================================================== >>> When responding to posts, please "Reply to Group" via your newsreader so >>> that others may learn and benefit from your issue. >>> ================================================== >>> This posting is provided "AS IS" with no warranties, and confers no >>> rights. >>> >> Hi Cj,
Thanks for your feedback! Based on my reading, your main concern is writing 2 fields to the memory table instead of 1 field. I think you have 2 choice to resolve this: 1. If one of your field is unique, you can use it as a key for lookup. Just as Cor suggested, you may use SortedList or Hashtable for storage, since they both use a key for lookup. So your first field is used as a key, and the other field is stored in the SortedList/Hashtable associated with the key(first field). This implementation is easy. 2. If your 2 fields are not unique, you can implement a customized class which contains 2 properties to store these 2 fields, and you may store this class instance in the System.Collections.* class. Choose what class in this namespace you want. Thanks. Best regards, Jeffrey Tan Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Override Printer Margins (?)
HTML links Pls Help me ,about GDI+ fill some image area text/xml reporting service error Windows Service and StreamWriter Serialize 3 levels of nested collections. DataGridView column sort avoiding - File download-security warning window when using response.writefile(filepath) DataGridView question multiple DatGridView in one form |
|||||||||||||||||||||||