|
Tristan Rhodes wrote: Would it be efficient to do something along these lines:
I'm presuming that cmdResponse will be set in the callback method on the other thread.
Tristan Rhodes wrote: And that should free up the db wait time for other requests?
What other requests? If my assumption is correct, you have taken an asynchonous request and effectively turned it back in to a synchronous request by waiting for the call back function to return.
Now, if you were to do something between the BeginInvoke and waiting for the call back method to populate cmdResponse then there might be some point.
When you are waiting for a database call to return from the server the thread will be blocked and the scheduler will skip past it until something is available for it to do.
|
|
|
|
|
I'm intrigued by the mechanics for this.
Clearly there is going to be a wait for the database response to process and return, and i'd like other threads to use that time instead of the current thread. I've been lead to believe that by performing a standard non async query, the thread is locked and not shared leading to a performance hit with lots of concurrent request, whilst performing a thread.sleep would enable it to be freed up and process other requests whilst waiting for the DB to response. In which case, wrapping an async operation in a Sleep loop would give up the thread whilst waiting for a response.
But i'm guessing i've got the wrong end of the stick. Where have i gone wrong?
Cheers
T
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Tristan Rhodes wrote: Clearly there is going to be a wait for the database response to process and return, and i'd like other threads to use that time instead of the current thread.
The thread will block while it waits for the network response. Just as it will block if it is waiting for a disk read and so on. While the thread is blocked the OS will switch to the next available highest priority non-blocked thread. The OS will not attempt to run blocked threads. So blocked threads will not take up processor time.
Tristan Rhodes wrote: the thread is locked and not shared leading to a performance hit with lots of concurrent request
Locking is a different issue.
Locking relates to resources. For example, if you are performing an update on an object that takes several lines of code the OS can interupt the operation and swap in a different thread (or the other thread may be running on a separate processor or core). Either way, while you are making the update you want to lock out any other changes so that your object remains in a consistent state. When you lock the object you block other threads from locking it at the same time.
If a thread attempts to lock an object that is already locked its will be blocked, the OS will move on to the next thread (the highest priority non-blocked thread). When the first thread releases the lock the second thread can then aquire it. For obvious reasons a lock should be aquired and released as quickly as possible, you don't want to block other threads too long.
Tristan Rhodes wrote: a thread.sleep would enable it to be freed up and process other requests whilst waiting for the DB to response
The thread will block anyway while waiting for the result set to return. You are just implementing what is already taken care of in the OS - and less efficiently because you continually wake up and perform a check then go back to sleep again. The synchronous database request will just wait (i.e. It will be blocked) until something is available or the operation times out.
Tristan Rhodes wrote: Where have i gone wrong?
By the looks of it confusing locking with blocking. I hope this has explained enough that you've got a better handle on the situation.
|
|
|
|
|
Sorry, i missused Lock in my last post, i know the difference.
Could you explain the benefits of using the Asynchronous PageLoad model in asp.net if, when waiting for requests from the database, the thread can process other incoming requests?
Cheers
T
Edit: Alternatively a good article will do. In the mean time, i will re-read the MS article on async programming model when i'm not so tired.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Hi!
I'm currently writing a poker program i .net compact framework. In one method I have a while-loop that goes through every player until everyone is finished betting. What I need is some way to halt the while-loop until the user makes a decision (presses a key) and then continue. How can I do this?
Thanks!
|
|
|
|
|
Have a Timer Control with Enabled = false.
Place the code that you wants to execute in the Timer_Tick Event .
Enable the Timer when the user press a key(In the Key Down event).
Hope hat helps you.
Regards,
Arun Kumar.A
|
|
|
|
|
If i have total markup (XAML) based workflow, how do i refer some property/variable defined in my XAML inside rule file?
I know how we can do this using code, but i want to do this for pure XAML based workflows.
Any hints or examples would be appreciated.
Muhammad Shoaib Khan
http://geocities.com/lansolution
|
|
|
|
|
hi i am currently doing remoting in c#.net window application my server codes is below
i would like to ask if there i can put an event handler (function)
which will execute when there is an incoming request from the client
reason: as i need to reload the form when also populate one of the text box in the form when the request comes in
thx for reading
and hope you can help me pls
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Runtime.Remoting;<br />
using System.Runtime.Remoting.Channels;<br />
using System.Runtime.Remoting.Channels.Tcp;<br />
<br />
namespace WindowsApplication2<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
TcpChannel channel = new TcpChannel(8080);<br />
ChannelServices.RegisterChannel(channel);<br />
<br />
RemotingConfiguration.RegisterWellKnownServiceType(<br />
typeof(ClassLibrary1.Class1),<br />
"HelloWorld",<br />
WellKnownObjectMode.SingleCall);<br />
}<br />
}<br />
}
|
|
|
|
|
I too am trying to work out how to do this.
What I know so far is that you need to use
WellKnownObjectMode.Singleton
When registering, this means that the server maintains 1 instance of the object and gives a reference (proxy) to this each time a client asks for it.
However How do we instantiate and get a reference to this object on the server side? so we can see the data its fields contain etc...
(Also remoting is not thread safe, AFAIK each remote call executes on an individual thread so you need to make them thread-safe).
Wilco
|
|
|
|
|
Hi
I have a problem with changing printer's paper size to custom paper size(programmatically).
I use PaperSize cunstuctor to create custom paper size and then assign it to PrintDocument.DefaultPageSettings.PaperSize.
this is not change paper size in printer.
Dim pd As PrintDocument = New PrintDocument
Dim pkCustomSize1 As New PaperSize("Custom", 100, 200)
pd.DefaultPageSettings.PaperSize = pkCustomSize1
Please Guide me
Thnaks
|
|
|
|
|
hi i am trying to do remoting so far i am able to connect but i cant seem to pass any data thru my code is as fellows:
i would too like to ask if my code is passing data from the sever to client or vise versa as i am a little confuse.
my server:
TcpChannel channel = new TcpChannel(8080);<br />
ChannelServices.RegisterChannel(channel);<br />
<br />
RemotingConfiguration.RegisterWellKnownServiceType(<br />
typeof(ClassLibrary1.Class1),<br />
"HelloWorld",<br />
WellKnownObjectMode.SingleCall);
my client:
TcpChannel chan = new TcpChannel();<br />
ChannelServices.RegisterChannel(chan);<br />
<br />
ClassLibrary1.Class1 obj = (ClassLibrary1.Class1)Activator.GetObject(<br />
typeof(ClassLibrary1.Class1),<br />
"tcp://172.17.168.51:8080/HelloWorld");<br />
<br />
try<br />
{<br />
if (obj.Equals(null))<br />
{<br />
label1.Text = "not connected";<br />
}<br />
else<br />
{<br />
label1.Text = "connected";<br />
}<br />
}<br />
catch<br />
{<br />
label1.Text = "not connected";<br />
}
my class:
public class Class1 : MarshalByRefObject<br />
{<br />
<br />
public Class1()<br />
{<br />
string abc; <br />
}<br />
<br />
<br />
<br />
<br />
}
as you can see my class contint a string abc i would like to ask how can i set it at my start and what code would i use to exttract it at the end side
|
|
|
|
|
Hi all..
Can anyone provide me with the code convertor tool...ie.the tool which converts the vb.net code to C# code and vice versa...
It would be better if the tool is an .exe..
Some one help in this regard as early as possible...
Note:Dont reply asking to try in google...
Regards,
Balaguru
|
|
|
|
|
Hi Balaguru,
First of all this is no service that you can get from this web site, that you can command for information. All you can do is to request for information, and be polite.
If somebody asks you to try in Google, it may be because its an obvious information. What you have asked here now is such a question. Code convertor tools are available in plenty and all you got to do is use google to find it. Forget google my friend, its available here in Code project.
http://www.codeproject.com/csharp/gbvb.asp
So first try some resources and only if you dont find any usefull information, post it here.
In my case, I dont have access to Google in my work place, still I post questions only after going through articles here. I do not mean any offence, but I hope many of our members would agree with me.
Regards,
Blumen
|
|
|
|
|
Hi Blumen...
I feel sorry if my post has insulted u...I dont find any commanding issues in my post rather i have made only a humble request..As like u i too dont have access to google in my office.Thats wat made me to make a note in my post.What happens is that we post a question and long for replies.If the reply simply comes try in google,its very irritating..Thats it..
Anyway i am sorry ...
Regards,
Balaguru
|
|
|
|
|
Balagurunathan S wrote: As like u i too dont have access to google in my office.
You need to make this clear. It's about the dumbest policy I ever heard of, so you're going to have to tell us that it's the case where you are.
http://www.tangiblesoftwaresolutions.com[^] is one of the hits I got with google.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
Your words dint insult me, I found it impolite, though. Anyways I hope you would have got useful information regarding the tool now. Try these as well:
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx
http://www.kamalpatel.net/ConvertCSharp2VB.aspx
Regards,
Blumen
|
|
|
|
|
Balagurunathan S wrote: Note:Dont reply asking to try in google...
So why is Google blocked at your workplace?
Yahoo too?
Seriously, all you had to do was type "vb.net c# converter" into either one and you'd come up with a bunch of them.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi Dave,
I've no idea why Google is blocked here, thank god we have access to CP
Yahoo is not blocked, we can use Yahoo search, but can't open any results because those websites would be blocked. I believe they are restricting Internet access to maintain safety of the code and of the network, from hacks and viruses. We can't access any personal e-mail, i.e. websites like Yahoomail, hotmail, gmail etc.
I don't think situation is the same in all companies here, some companies give unrestricted access to its employees.
From which part of the world are you from Dave, and how is network maintained in your company? I'm from India. I hope its liberal there.
Regards,
Blumen
I wish to become a software consultant.
|
|
|
|
|
Quit and find a better company. Well, find a better compnay first, then quit. If the search engines are useless to you, I don't see how they can expect you to find solutions to problems without the 'Net.
I'm in the US and in the company I work for, there are no blocks on where I can go.
|
|
|
|
|
Balagurunathan S wrote: Dont reply asking to try in google...
Why not?
If google can't do it, then look at Sharpdevelop because they have a tool for converting VB.NET to C#. I haven't worked with it in a long time, so I don't know how well it converts...
|
|
|
|
|
SharpDevelope's conversion tool for VB-C# isn't that good. C#-VB support is OK though. I find that when converting VB-C# code, SharpDevelop doesn't take into account VB Optional keyword. It leaves it in there, and of course the C# compiler doesn't understand it. I had to really revamp my code and include support for multiple extra functions before I got my app working OK.;)
|
|
|
|
|
There are some RASEnumEntries projects written in VB6. However there isn't any project written in vb.net in the Internet. I have tried converting a VB6 project into VB.Net but i hit the 632 - Invalid size error. Can someone enlighted me? Here are part of my source code:
'Structure for RASENTRYNAME (Did i get the structure rite?)
'==============================================
Private Structure RAS_ENTRIES
Dim dwFlags As Integer
Dim dwSize As Integer
<vbfixedarray(256)> Dim szEntryname() As Byte
Public Sub Initialize()
ReDim szEntryname(256)
End Sub
End Structure
'==============================================
Function RasEnumEntriesA (Am i assigning the correct structure size?)
'==============================================
Dim lngSize As Integer
Dim lngEntries As Integer
Dim lngIndex As Integer
Dim result As Long
Dim RAS(255) As RAS_ENTRIES
Erase sDunList
RAS(0).dwSize = Marshal.SizeOf(RAS(0))
lngSize = 256 * RAS(0).dwSize
result = RasEnumEntriesA(vbNullString, vbNullString, RAS(0), lngSize, lngEntries)
'================================================
Any help is appreciated. Thanks alot!
Regards,
Max
|
|
|
|
|
It's a pain converting from VB6 to VB.NET, especially when you start calling into the Win32 API. VB6 and VB.NET differ in the way functon parameters are mashaled back and forth. This call in particular, is a b**** to get running.
First, you need to clean up the RAS_ENTRIES structure a bit. You need to tell the .NET CLR how to pack structure members together and how to pass the strings so it matches what the API expects. You also have to tell the CLR what the maximum size the strings are going to be when they are marshaled back to managed code.
<StructLayout(LayoutKind.Sequential,CharSet:=CharSet.Unicode)> _
Public Structure RASENTRYNAME
Public dwSize As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public szEntryName As String
Public dwFlags As Integer
<MarshalAs(UnmanagedType.ByValTStr,SizeConst=261)> Public szPhonebook As String
End Structure
You didn't post what you put for the Declare, but it should look something like this:
Private Declare Auto Function RasEnumEntries Lin "rasapi32" ( _
ByVal reserved As String, _
ByVal phonebook As String, _
<[In](), Out()> ByVal RasEntries() AS RASENTRYNAME, _
ByRef BufferSize As Integer, _
ByRef EntryCount As Integer) _
As Integer
To call it, you have to be a little careful. You have to create an empty dummy entry and set the entries internal structure size before you call this function:
Dim bufferSize As Integer = Marshal.SizeOf(GetType(RASENTRYNAME))
Dim entryCount As Integer = 1
Dim entryNames(0) As RASENTRYNAME
Dim returnCode As Integer
entryNames(0).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
If rc = 0 Then
' Return, there was only one entry and it's been filled into the "dummy"
' entry that we made before calling RasEnumEntries.
End If
If rc <> 603 Then
' So if we get here, the call bombed. It would be a good idea to find out why here!
Return
End If
' 603 means that there are more entries than we have allocated space for.
' So, expand the entryNames array and make sure we fill in the structure size
' for every entry in the array! This is important!! Without it, you'll get 632 errors!
ReDim entryNames(numEntries - 1)
For i As Integer = 0 to numEntries - 1
entryNames(i).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
Next
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
'
' Now we should have all the Ras entries. Do with as you will...
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi Dave,
I got your advise. Finally the codes are running fine with the result i want.
Many thanks to u!!
Best Rdgs,
Max
|
|
|
|
|
@Dave: your code works perfectly, but on my side some cleanup was required.
So I decided to post a complete and clean version...
Private Const MAX_PATH As Integer = 260 + 1
Private Const MAX_RAS_ENTRY_NAMES As Integer = 256 + 1
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure RASENTRYNAME
Public dwSize As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_RAS_ENTRY_NAMES)> _
Public szEntryName As String
Public dwFlags As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> _
Public szPhonebook As String
End Structure
Private Declare Auto Function RasEnumEntries Lib "rasapi32.dll" ( _
ByVal reserved As String, _
ByVal phonebook As String, _
<[In](), Out()> ByVal RasEntries() As RASENTRYNAME, _
ByRef BufferSize As Integer, _
ByRef EntryCount As Integer _
) As Integer
''' <summary>
''' Returns an array with available RAS connection names
''' </summary>
Public Shared Function GetConnectionsNames() As String()
Dim res As New List(Of String)
Try
Dim bufferSize As Integer = Marshal.SizeOf(GetType(RASENTRYNAME))
Dim entryCount As Integer = 1
Dim entryNames(0) As RASENTRYNAME
Dim rc As Integer
entryNames(0).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
If rc = 0 Then
' There was only one entry and it's been filled into the "dummy"
' entry that we made before calling RasEnumEntries.
res.Add(entryNames(0).szEntryName.Trim)
ElseIf rc = 603 Then
' 603 means that there are more entries than we have allocated space for.
' So, expand the entryNames array and make sure we fill in the structure size
' for every entry in the array! This is important!! Without it, you'll get 632 errors!
ReDim entryNames(entryCount - 1)
For i As Integer = 0 To entryCount - 1
entryNames(i).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
Next
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
For i As Integer = 0 To entryCount - 1
res.Add(entryNames(i).szEntryName.Trim)
Next
Else
' So if we get here, the call bombed. It would be a good idea to find out why here!
MsgBox("Error reading RAS connections names, error code:" & rc.ToString(), MsgBoxStyle.SystemModal)
End If
Catch ex As Exception
MsgBox("Error reading RAS connection names: " & ex.Message.ToString(), MsgBoxStyle.SystemModal)
End Try
Return res.ToArray
End Function
Thanks again.
Caudio
|
|
|
|
|