|
i have two homework:
the first homework :when i use Directory.GetCurrentDirectory(),it return current dirrector is debug directory
the second one:it return Release Directory
I don't understand when return Realeas and When return Debug
please help me
thanks
|
|
|
|
|
Actually GetCurrentDirectory Method returns the last directory used in your application
Obviously when you call it at first you will get the executable path directory so if you set the build mode to Debug it will give you the Debug path and if you set it to Release mode it will give you Release path.
and if you browse another path in your program you will have it if you call GetCurrentDirectory method
hope the post help
|
|
|
|
|
If you build your application under the Debug configuration in Visual Studio (or just hit F5 to start the app under the debugger), it will use the Debug directory. If you build your app using the Release configuration in Visual Studio, it will use the Release directory. Simply put, that's where the built .exe goes when you build your application.
|
|
|
|
|
Hi All,
I have a listview with two columns and in my first column i m creating a textbox when i double click the listviewitem.And i have context menu for listview by which when there is any item selected and i press Del it will delete the selected item .Now , when i m in textbox and i write something and press to Del to delete a character it deletes the listviewitem while i want to delete only the character.
How can i fix it , please give me some help.
Thanx.
Praveen Sharma
|
|
|
|
|
Are you sure you use ListView.KeyPress Event for deleting an Item ?
|
|
|
|
|
No i m not using it , i m using context menu and for deleting a item i have set the shortcut key (Delete), but when i m in the textbox and i want to delete a character in textbox and press Delete key the message for deleting the listview item is coming up which i don't want i only want to delete a listviewitem when i m not in the textbox.
Praveen Sharma
|
|
|
|
|
Hello,
I would like to use a progress bar to monitor the loading of my data grid. I would like some help in selecting the best events in the bindingsource and/or DataGridView to increment the progress bar on my screen and setting the maximum value to increment too.
I tried using DataGridView.RowCount for the maximum value of the pbar and the event GridRowsAdded to increment the value but I get an error when I filter the data using a dataview since the RowCount is not accurate until the DataGridView is populated.
Is there an event in the bindingSource that would give me the maximum value before the data is added to the grid? Or is there some other way to do this that makes more sense?
The previous help on this board helped my solution and I appreciate that. Thanks.
Boyd
Boyd
|
|
|
|
|
Does anybody know if there's a way to interact with a printer that prints onto CD's? I've googled it and haven't found anything promising. The app that I'm writing is going to need it. Any ideas?
may your code be error free
|
|
|
|
|
The code below reads data from a binary file into an instance, then writes that instance to an instance array (forgive me if my terminology is wrong, I'm self taught ^^)
The first time it runs through the loop it works fine, but as it goes through the second iteration it begins to over write the data in ItemsArray[0], even though the counter c is now 1 AND i haven't even told it to write to the array.
It is as if it were writing the data to the array before being told to :s
I hope I've made the problem clear, if not, just ask for clarification
Am i making an obvious error?
Thanks ^^
Items[] ItemsArray = new Items[NumberOfRecords];<br />
Items Item = new Items();<br />
<br />
int c = 0;<br />
<br />
while (c < NumberOfRecords)<br />
{<br />
bw.Seek((c * 180), SeekOrigin.Begin);<br />
Item.SetName(br.ReadString());
bw.Seek((c * 180) + 40, SeekOrigin.Begin);<br />
Item.SetItemType(br.ReadString());<br />
bw.Seek((c * 180) + 60, SeekOrigin.Begin);<br />
Item.SetDescription(br.ReadString());<br />
bw.Seek((c * 180) + 160, SeekOrigin.Begin);<br />
Item.SetWeight(br.ReadInt32());<br />
Item.SetWeaponDamage(br.ReadInt32());<br />
Item.SetWeaponRange(br.ReadInt32());<br />
Item.SetWeaponMultiShot(br.ReadInt32());<br />
Item.SetArmourRate(br.ReadInt32());<br />
<br />
ItemsArray[c] = Item;
<br />
<br />
c++;<br />
<br />
}
|
|
|
|
|
in your iterations you didn't create a new instance of your object Items because it's out of the while loop and because it's a reference type you simply write in it again and just create a new pointer ItemsArray[c] to it so all Data in the ItemsArray would be the same
for solving this, just put the Items Item =new Item(); inside the while Loop and it would be solved I think
good luck
|
|
|
|
|
It is because you are putting the same Item in every slot in the array. You need to put the line:
Items Item = new Items();
inside the loop.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
hi
you assign Item only once. so each time you say itemsArray[c] = Item; , you assign the same object go another item in your array. but it's just a reference. so if you do anything with the object by calling Item.SetName(...) you modify the object that's referenced by multiple entries in your array.
calling Item = new Items() after ItemsArray[c] = Item; should help you out
greets
m@u
|
|
|
|
|
Maybe Item is a reference type, so you're always setting the same item and your list will always hold the same item in the entire list.
better use
List<Items> itemsArray = new List<Items>(NumberOfRecords)
and then in the loop always create a new item and append it, like that:
int c = 0;
while(c < NumberOfRecords)
{
Items item = new Item();
itemsArray.Add(item);
c++;
}
<pre>
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks for all the replys!
Ill do that, thanks a lot!
|
|
|
|
|
|
Hi,
I'm activating software installations on a network but in a very manual way. First pinging the network for active computers, compare actives computers with an installation list then executing a bat on the computer. I thought it should be easy to automate the process and started reading up on the System.Net.NetworkInformation library but the problem is that I don't know how to extract the computer name from the pingReply object.
It only returns the IP address and since the DNS lookup table isn't up to date I can't use that.
Is there another way to get a computers name from the IP address
Thanks
WvdW
|
|
|
|
|
WvdW wrote: then executing a bat on the computer
[the CodeProject PoliticallyCorrectBot has removed some comments from this post]
hope that helps
|
|
|
|
|
Dns.Resolve method will get you the name
however I said before in another post the method is obsolete and Microsoft recommends to use Dns.GetHostEntry method instead of it but that method didn't give me the name of computers on our network except mine maybe there is a trick on using that!.
good Luck
|
|
|
|
|
Thanks
I guess I'll have rewrite it for myself or open a cmd and get the reply from there.
Enjoy the rest of your day
WvdW
|
|
|
|
|
I just had it in my archive maybe simplify your work but it in VB
<br />
<br />
Option Explicit<br />
<br />
'// define constants<br />
Private Const IP_SUCCESS As Long = 0<br />
Private Const SOCKET_ERROR As Long = -1<br />
<br />
Private Const MAX_WSADescription As Long = 256<br />
Private Const MAX_WSASYSStatus As Long = 128<br />
Private Const MIN_SOCKETS_REQD As Long = 1<br />
<br />
Private Const WS_VERSION_REQD As Long = &H101<br />
'Private Const WS_VERSION_MAJOR As Long = WS_VERSION_REQD / &H100 And &HFF&<br />
Private Const WS_VERSION_MINOR As Long = WS_VERSION_REQD And &HFF&<br />
<br />
Private Const WSADescription_Len As Long = 256<br />
Private Const WSASYS_Status_Len As Long = 128<br />
Private Const AF_INET As Long = 2<br />
<br />
'// structures<br />
<br />
Private Type HOSTENT<br />
hName As Long<br />
hAliases As Long<br />
hAddrType As Integer<br />
hLength As Integer<br />
hAddrList As Long<br />
End Type<br />
<br />
<br />
Private Type WSADATA<br />
wVersion As Integer<br />
wHighVersion As Integer<br />
szDescription(0 To MAX_WSADescription) As Byte<br />
szSystemStatus(0 To MAX_WSASYSStatus) As Byte<br />
wMaxSockets As Long<br />
wMaxUDPDG As Long<br />
dwVendorInfo As Long<br />
End Type<br />
<br />
'
'kernel32<br />
Private Declare Sub apiCopyMemory Lib "kernel32" Alias "RtlMoveMemory" (xDest As Any, xSource As Any, ByVal nBytes As Long)<br />
Private Declare Function apiStrLen Lib "kernel32" Alias "lstrlenA" (lpString As Any) As Long<br />
'wsock32<br />
Private Declare Function apiGetHostByName Lib "wsock32.dll" Alias "gethostbyname" (ByVal hostname As String) As Long<br />
Private Declare Function apiWSAStartup Lib "wsock32.dll" Alias "WSAStartup" (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long<br />
Private Declare Function apiWSACleanup Lib "wsock32.dll" Alias "WSACleanup" () As Long<br />
Private Declare Function apiInetAddr Lib "wsock32.dll" Alias "inet_addr" (ByVal s As String) As Long<br />
Private Declare Function apiGetHostByAddr Lib "wsock32.dll" Alias "gethostbyaddr" (haddr As Long, ByVal hnlen As Long, ByVal addrtype As Long) As Long<br />
<br />
'// private functions<br />
Private Function InitializeSocket() As Boolean<br />
Dim WSAD As WSADATA<br />
<br />
'attempt to initialize the socket<br />
InitializeSocket = apiWSAStartup(WS_VERSION_REQD, WSAD) = IP_SUCCESS<br />
End Function<br />
<br />
Private Sub CloseSocket()<br />
'try to close the socket<br />
If apiWSACleanup() <> 0 Then<br />
MsgBox "Error calling apiWSACleanup.", vbCritical<br />
End If<br />
<br />
End Sub<br />
<br />
Public Function GetIPFromHostName(ByVal sHostName As String) As String<br />
'converts a host name to an IP address.<br />
<br />
Dim nBytes As Long<br />
Dim ptrHosent As Long<br />
Dim hstHost As HOSTENT<br />
Dim ptrName As Long<br />
Dim ptrAddress As Long<br />
Dim ptrIPAddress As Long<br />
Dim sAddress As String 'declare this as Dim sAddress(1) As String if you want 2 ip addresses returned<br />
<br />
'try to initalize the socket<br />
If InitializeSocket() = True Then<br />
<br />
'try to get the IP<br />
ptrHosent = apiGetHostByName(sHostName & vbNullChar)<br />
<br />
If ptrHosent <> 0 Then<br />
<br />
'get the IP address<br />
apiCopyMemory hstHost, ByVal ptrHosent, LenB(hstHost)<br />
apiCopyMemory ptrIPAddress, ByVal hstHost.hAddrList, 4<br />
<br />
'fill buffer<br />
sAddress = Space$(4)<br />
'if you want multiple domains returned,<br />
'fill all items in sAddress array with 4 spaces<br />
<br />
apiCopyMemory ByVal sAddress, ByVal ptrIPAddress, hstHost.hLength<br />
<br />
'change this to<br />
'CopyMemory ByVal sAddress(0), ByVal ptrIPAddress, hstHost.hLength<br />
'if you want an array of ip addresses returned<br />
'(some domains have more than one ip address associated with it)<br />
<br />
'get the IP address<br />
GetIPFromHostName = IPToText(sAddress)<br />
'if you are using multiple addresses, you need IPToText(sAddress(0)) & "," & IPToText(sAddress(1))<br />
'etc<br />
End If<br />
Else<br />
MsgBox "Failed to open Socket."<br />
End If<br />
End Function<br />
<br />
Private Function IPToText(ByVal IPAddress As String) As String<br />
'converts characters to numbers<br />
IPToText = CStr(Asc(IPAddress)) & "." & _<br />
CStr(Asc(Mid$(IPAddress, 2, 1))) & "." & _<br />
CStr(Asc(Mid$(IPAddress, 3, 1))) & "." & _<br />
CStr(Asc(Mid$(IPAddress, 4, 1)))<br />
End Function<br />
<br />
Public Function GetHostNameFromIP(ByVal sIPAddress As String) As String<br />
<br />
Dim ptrHosent As Long<br />
Dim hAddress As Long<br />
Dim sHost As String<br />
Dim nBytes As Long<br />
<br />
'try to open the socket<br />
If InitializeSocket() = True Then<br />
<br />
'convert string address to long datatype<br />
hAddress = apiInetAddr(sIPAddress)<br />
<br />
'check if an error ocucred<br />
If hAddress <> SOCKET_ERROR Then<br />
<br />
'obtain a pointer to the HOSTENT structure<br />
'that contains the name and address<br />
'corresponding to the given network address.<br />
ptrHosent = apiGetHostByAddr(hAddress, 4, AF_INET)<br />
<br />
If ptrHosent <> 0 Then<br />
<br />
'convert address and<br />
'get resolved hostname<br />
<br />
apiCopyMemory ptrHosent, ByVal ptrHosent, 4<br />
<br />
nBytes = apiStrLen(ByVal ptrHosent)<br />
<br />
If nBytes > 0 Then<br />
'fill the IP address buffer<br />
sHost = Space$(nBytes)<br />
<br />
apiCopyMemory ByVal sHost, ByVal ptrHosent, nBytes<br />
GetHostNameFromIP = sHost<br />
End If<br />
Else<br />
MsgBox "Call to gethostbyaddr failed."<br />
End If<br />
'close the socket<br />
CloseSocket<br />
Else<br />
MsgBox "Invalid IP address"<br />
End If<br />
Else<br />
MsgBox "Failed to open Socket"<br />
End If<br />
End Function<br />
<br />
<br />
|
|
|
|
|
Thanks
Just scanned it but the 'GetHostNameFromIP' looks promising.
Luckily vb is not that difficult to convert to C#.
Hope you have a great day
WvdW
|
|
|
|
|
Hello,
I posted this on msdn thread too but haven't gotten any answer yet so was wondering if you guys can help.
===================
Ahh question about accessing Windows form from a thread created through thread.
When I tried to make sure it's thread-safe, it keeps looping back into InvokeRequired because for some reason the calling thread and creating thread are never the same... Here's a watered down example...
private void blahblahblah()<br />
{<br />
<br />
Thread t = new Thread(method);<br />
t.Start(); <br />
<br />
}<br />
<br />
private void method()<br />
{<br />
<br />
if(InvokeRequired)<br />
{<br />
<br />
<br />
}<br />
<br />
else<br />
{<br />
<br />
for(int i = 0; i < Number; i++)<br />
{<br />
<br />
<br />
Timer timer = new Timer();<br />
timer.Elapsed += new ElapsedEventHandler(andAnother);<br />
_Event.WaitOne();<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
private void andAnother()<br />
{<br />
<br />
if(InvokeRequired)<br />
{<br />
<br />
<br />
EventHandler Handler = new EventHandler(andAnother);<br />
this.Invoke(Handler, sender, e);<br />
<br />
}<br />
<br />
else<br />
{<br />
<br />
<br />
_Event.Set();<br />
<br />
}<br />
<br />
}
So on both threads, I want to access Windows Form. The first thread is good but the second thread that was created through the first thread loops through InvokeRequired.
Thanks!
|
|
|
|
|
Two pieces of information are missing:
- in what class is all this code, i.e. whose InvokeRequired are you using ?
- and what thread created the instance of that class having the problem ?
The comments don't match with the code:
- "Do something to Windows Form" and what you do is create a Timer (without sufficient
initialization I would say)
- "Doing something to Windows Form" and what you do is set an event.
Furthermore, the GUI thread should not be kept waiting on something.
ictoane wrote: it keeps looping back
what exactly does that mean ? are you getting a StackOverflowException ?
please provide exact code, with proper comment, and the symptoms that go with it.
The better your question is, the sooner you will get a good answer.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hello,
The comments "Do something to Windows Form" are replacements for codes dealing with Windows Forms to eliminate unncessary blocks of code that are irrelevant to the question. I just left them out because they're basically doing something to Windows Form like setting up the ProgressBar or changing the Label.
Basically I want to have a method that creates two threads. And for each of those two threads, create System.Timers.Timer to call on an event to update the ProgressBar and other Windows Forms every second. The two threads need to start on the same time but performs different tasks so I can't skip the threads and go immediately to Timers.
I want to interact with Windows Form on the first layer thread as well as the second layer thread. The way to call Controls in a thread safe manner is to use if(this.InvokeRequired) (<a href="http://msdn2.microsoft.com/en-us/library/ms171728(VS.80).aspx">)</a>[<a href="http://msdn2.microsoft.com/en-us/library/ms171728(VS.80).aspx" target="_blank" title="New Window">^</a>). However, this doesn't work when I use it on the second layer thread.
Therefore, the problem I'm getting is that whenever I use this.InvokeRequired on the second layer thread created by the first layer thread, "it keeps looping back". I'm not intentionally making it to loop back.
Thanks
|
|
|
|
|
Your biggest problem with this code is that the _Event.WaitOne(); is causing the GUI thread to wait until signalled.
This is a great example of a deadlock situation.
Phil
|
|
|
|