![](https://www.xtremedotnettalk.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
MrPaul
Avatar/Signature-
Posts
440 -
Joined
-
Last visited
About MrPaul
- Birthday 01/11/1984
Personal Information
-
Occupation
Software developer
-
Visual Studio .NET Version
Visual Studio 2005
-
.NET Preferred Language
C#
MrPaul's Achievements
Newbie (1/14)
0
Reputation
-
Pick two and swap! There certainly is a simpler way of achieving this. If your intent is to create a list containing all numbers from LowVal to HighVal, in a random order, the simplest solution is to add them all to the list sequentially, and then jumble them up by repeatedly swapping two randomly chosen items. This is easiest/fastest with an array. The reason this is preferable, is that your implementation will take an indeterminate amount of time to execute. The more items that get added to the list, the more "collisions" will occur - to the point that for the last value, the loop has to keep generating random numbers until the one possible valid number is randomly chosen. For large values of HighVal, this could take forever! Compare this to the "swap items randomly" method, which will have a predictable number of swaps, and therefore a predictable time function. Good luck! :cool:
-
Drawing to a panel when clicking a button?
MrPaul replied to diabolos's topic in Graphics and Multimedia
Call panel1.Invalidate() when needed You put Panel1.Invalidate() in the paint event handler? Each time you call Panel1.Invalidate(), the paint event will be called and the panel will be redrawn. You should only be calling Panel1.Invalidate() when you want to redraw the panel - it sounds like this will be in two places: In the event handler for your "Go!" button (after populating the boolean values) In the event handler for your "step" button (after updating the values) However, the paint event could be called at any time, for example when the form is shown or when a window which was obscuring the panel is moved away. To compensate for this, your paint event handler needs to check whether "Go!" has been clicked. For example: Dim goPressed As Boolean = False Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint If (goPressed) Then 'Draw game state End If End Sub Private Sub btnSeed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeed.Click 'Populate values 'Draw panel goPressed = True Panel1.Invalidate() End Sub Private Sub btnStep_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStep.Click 'Update values 'Redraw panel Panel1.Invalidate() End Sub Good luck :cool: -
Managing your own synchronicity Using asynchronous methods is never going to be as simple as using synchronous methods, and you are unlikely to ever get language that supports what you are suggesting. To have an assignment which completes non-deterministically would probably lead to some very difficult to diagnose bugs! A different approach would be to handle the synchronicity yourself - kick off the operation a new thread directly from the button event handlers, and then use synchronous methods to do the work: void button1_handler(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem(PopulateList, "button1"); } void button2_handler(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem(PopulateList, "button2"); } void PopulateList(object state) { listBox1.ItemsSource = dal.GetList((string) state); //Do other work here } This keeps the program flow nice and logical. Good luck :cool:
-
Search and Quick Links menus dont work in Chrome
MrPaul replied to MrPaul's topic in Suggestions, Bugs, and Comments
Problem with User-Agent detection? I found this on another forum running vBulletin: Possibly something that could be fixed by the admins of this forum then, or would that be wishful thinking? :rolleyes: -
ShowDialog() not Show() You need to use the ShowDialog() method to show the About form, not Show(): AboutForm about = new AboutForm(); about.ShowDialog(); Good luck :cool:
-
Optimization Thinking about it, if you plan to use & to unset the ReadOnly and Hidden bits, you don't really need to be doing the comparison, as the operation will have no effect if the bits are not set. This means your code can be simplified to: static bool FileExists(string file) { if (File.Exists(file)) { FileInfo fi = new FileInfo(file); if ((fi.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { return false; } //Always unset ReadOnly bit fi.Attributes &= ~FileAttributes.ReadOnly; //Always unset Hidden bit fi.Attributes &= ~FileAttributes.Hidden; return true; } else { return false; } } Good luck :cool:
-
Imports statement Assuming you're using VB.NET, you need to have the following line at the top of your source file: Imports System.IO The following declarations would also be useful: Option Strict On Option Explicit On You can find explanations of these statements on MSDN. Good luck :cool:
-
Not unsetting ReadOnly or Hidden! The & operator does not unset bits. It can be used to unset a bits, but first you need to invert (not) the bitmask: //This makes it so that ONLY ReadOnly is set: fi.Attributes &= FileAttributes.ReadOnly; //This unsets ReadOnly: fi.Attributes &= ~FileAttributes.ReadOnly; Lets see why: fi.Attributes: 00100001 (Archive and ReadOnly) ReadOnly : 00000001 & of above : 00000001 (just ReadOnly) fi.Attributes: 00100001 (Archive and ReadOnly) ~ReadOnly : 11111110 & of above : 00100000 (just Archive) Good luck :cool:
-
Redirect the output using .NET Redirection using > is a function of the Windows shell interpreter. To get this to work you would need to launch cmd.exe directly (or via a batch file as Nate suggests). A better solution would be to capture the output of the MySqlDump.exe process and write it to a file. The following thread shows how to do this: Redirect Standard Output of a Process with window hidden? [C# 2002] Good luck :cool:
-
The origins of 4k I believe the size of 4096 (4kB) most likely came into common usage as it is historically the default size of a memory page on x86, meaning it represented a good size/speed tradeoff. It is a value I generally use for data buffers. The chunk approach is definitely preferable - in certain situations I even go as far as to copy data a byte at a time. Good luck :cool:
-
Ping If the server periodically sends a "ping" style message to the client, eventually network failures will be detected by the underlying transport protocols and then get propagated back to your server application to handle appropriately. Good luck :cool:
-
Debugging It sounds very likely that your initDirect3D function is failing, and your program exits before the message processing loop. Your first step should be to verify that this is the case - add some printf statements liberally at critical points - when working with things like DirectX it can be a lot easier to debug this way than stepping through. For example, this is how I'd add debugging statements to initDirect3D: bool initDirect3D(void) { HRESULT hResult = D3D_OK; printf("Entered function initDirect3D\n"); pD3D = NULL; pd3dDevice = NULL; // Create the DirectX object pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if (pD3D == NULL) { printf("Direct3DCreate9 failed. pD3D == NULL\n"); return false; } printf("IDirect3D9 was created successfully\n"); // Fill the presentation parameters structure D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof( d3dpp ) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 1; d3dpp.BackBufferHeight = 480; d3dpp.BackBufferWidth = 640; d3dpp.hDeviceWindow = wndHandle; // Create a default DirectX device hResult = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, wndHandle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice ); if (hResult != D3D_OK) { printf("pD3D->CreateDevice failed. hResult = %i\n", hResult); switch (hResult) { case D3DERR_INVALIDCALL: printf("hResult = D3DERR_INVALIDCALL\n"); break; case D3DERR_DEVICELOST: printf("hResult = D3DERR_DEVICELOST\n"); break; case D3DERR_NOTAVAILABLE: printf("hResult = D3DERR_NOTAVAILABLE\n"); break; case D3DERR_OUTOFVIDEOMEMORY: printf("hResult = D3DERR_OUTOFVIDEOMEMORY\n"); break; default: printf("Unknown hResult\n"); } return false; } printf("Device created successfully\n"); return true; } Add similar changes to the rest of your code, and debugging these sorts of problems will become much easier - just by looking at the console output of your program, you will be able to locate the area of code which is the source of the problem, and then take steps to correct it. I could well be wrong about the problem being in the initDirect3D function, but without some sort of debugging facility, it is impossible to tell! Good luck :cool:
-
Cannot serialize types in XML This is a quirk of XML serialization - it cannot serialize types. Just try and serialize any type using the XmlSerializer and you will get an exception of some sort. The only solution is to represent each type in some other form (e.g. string), or use a different serialization formatter. Good luck :cool:
-
Adding a reference to a non-COM component.
MrPaul replied to Nikolas II's topic in Interoperation / Office Integration
Using a standard DLL If it isn't a .NET or COM DLL, then it is likely that the DLL is a "standard" DLL which exports one or more functions. There are tools which allow you to find out the names of functions exported by a DLL, but the names and even signatures of the functions are unlikely to be enough to know how to use the DLL properly. Calling standard DLL functions from .NET can be achieved using DllImport and marshalling. This is a common technique for invoking native Win32 functions, and there is plenty of information in these forums relating to that - providing, of course, you know how the DLL works. Do you have any documentation for the DLL? Good luck :cool: