|
Member 12061600 wrote: that I am guarded against someone removing USB How can you? If someone unplugs a physical device then the link is broken. The issue is how your program caters for, and recovers from, such a contingency. As with all programming you need to design for all situations.
Member 12061600 wrote: I know what debugging is but issue seems not trivial. That may be true, but it is still the best way to track down problems.
|
|
|
|
|
How can you? If someone unplugs a physical device then the link is broken. The issue is how your program caters for, and recovers from, such a contingency. As with all programming you need to design for all situations.
It seems I can check my first response to you.
When I open all the time port and then close in finally.
That way it seems to work always.
I am interested what are drawbacks of that.
|
|
|
|
|
Member 12061600 wrote: I am interested what are drawbacks of that. Port might be occupied by another application, or the user might have plugged into another port.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I would look into HASP detection. That will dictate what you need to do; even if it means disposing of the serial port and reopening it.
Google[^]
|
|
|
|
|
In using web services in VS 2010, I get the error. In the app.config, I added "readerQuotas" and also increased the maxBufferSize, maxBufferPoolSize and maxReceivedMessageSize to no avail.
I can successfully make a call where there is no date contained in the response. Using SoapUI 5.2.1, I discovered that the format of the date is "1969-11-05T00:00:00-08:00". One suggestion I found is to change the "System.Datetime" data types to "string" in the Reference.cs file. But that did not work either.
Any insights would be appreciated.
|
|
|
|
|
The reference file is generated from the service definition; you may not get far without changing the service. (Maybe your reference file is out of date).
Not much info. I would set breakpoints on the class setters / constructor and see where the problem is.
If you need to convert your "date string", the following will work:
DateTime dt = Convert.ToDateTime( "1969-11-05T00:00:00-08:00" );
Lastly, you can trace both client and server at the same time if you have a local test web server / project.
|
|
|
|
|
Context: recently I have been reviewing my understanding of different options for creating constructors for .NET classes by method-overloading, and using named, and optional, parameters.
My "habit," now, is to use multiple constructors (method-overloading), and use the 'ctor modifiers 'base, and 'this as necessary.
But, consider I define a lame POCO like this:
public class SomeClass
{
public int? SomeInt1 { private set; get; }
public int? SomeInt2 { private set; get; }
public string SomeString { private set; get; }
public SomeClass(int? someint1 = null, int? someint2 = null, string somestring = null)
{
SomeInt1 = someint1;
SomeInt2 = someint2;
SomeString = somestring;
}
} Using named parameters give me a lot of flexibility in constructing instances:
SomeClass sc1 = new SomeClass();
SomeClass sc2 = new SomeClass(someint1: 100);
SomeClass sc3 = new SomeClass(somestring: "hello");
SomeClass sc4 = new SomeClass(someint1: 999, someint2: 345, somestring: "goodbye");
SomeClass sc5 = new SomeClass(somestring: "hello", someint2: 555); In theory the use of nullable Int32 here means I can assume ... for a given instance of the Class ... that if one of the 'ints is null, it is not initialized. Curious what you think of using nullable ValueTypes in this way in 'ctors.
I think it's a useful feature of named parameters that in VS IntelliSense will show you the names as you type a 'ctor invocation, and I like the "constraint" that named parametrs can only appear after all positional parameters, and that this:
SomeClass sc6 = new SomeClass("hello and goodbye", someint1: 999, someint2: 345);
Produces an "argument mismatch" compile-time error.
But, using 'named arguments does increase the typing you'll do, and optional parameters, possibly, ... I think you could argue ... "weakens" the strong-typing nature of your code.
Curious what your thoughts are on 'ctor writing best practice.
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
modified 9-Feb-16 9:16am.
|
|
|
|
|
BillWoodruff wrote: optional parameters, possibly, ... I think you could argue ... "weakens" the strong-typing nature of your code. Why? They don't negate the need to explicitly set a type and adhere to its constraints. All it is, is a shortcut way of avoiding having to write multiple variations of constructor. I would argue, though, if you're needing to cope with so many optional parameters, it's a fair indication that your class is trying to do far too much. I've yet to see a case where a class adhering to SRP would need to have so many possible constructors.
This space for rent
|
|
|
|
|
Thanks, Pete, as always, for your enlightening comments. I have been using 'named and 'optional parameters for a while, and I do encounter tasks where several parameters are required. As much as I admire "SRP" as a philosophy, imho it doesn't mean that a single responsibility cannot be ... complex.
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
|
|
|
|
|
I would love to see one of your examples where it's SRP and having several parameters. As I said, I haven't encountered a case where it hasn't been an indication of a violation, so I really would love to see a case.
This space for rent
|
|
|
|
|
If you're looking at the various ways to create immutable classes, you might be interested in Jon Skeet's recent NDC video:
The changing state of immutability C# - Jon Skeet on Vimeo[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Extremely interesting video from the person I consider a "guru's guru" of .NET (along with Eric Lippert, Marc Gravell, and a few others).
thanks, Bill
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
|
|
|
|
|
I am try main first game, and have problem with terrain creatin. When i am load and use large texture is ok, when i am moving in game crash program with this message:
System.OutOfMemoryException: Out of memory.
at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromFile(String filename)
at sls.go.GoPaint(Object sender, PaintEventArgs e) in c:\Users\Jozef\Documenty\SharpDevelop Projects\sls\sls\go.cs:line 93
at System.Windows.Forms.Control.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Form.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Here is source code:
using System;
using System.Drawing;
using System.Windows.Forms;
using PlaySound;
using System.Drawing.Drawing2D;
namespace sls
{
public partial class go : Form
{
public go()
{
InitializeComponent();
}
int RotatePlayerinfo = 0;
int TempMatrixX = 0;
int TempMatrixY = 0;
bool left;
bool right;
bool up;
bool down;
void GoLoad(object sender, EventArgs e)
{
this.Cursor = Cursors.Cross;
this.ControlBox = false;
this.WindowState = FormWindowState.Maximized;
this.DoubleBuffered = true;
Refresh.Interval = 50;
Refresh.Enabled = true;
PlayerInfo.Interval = 500;
PlayerInfo.Enabled = true;
PlayerMoving.Interval = 50;
PlayerMoving.Enabled = true;
this.Paint += new PaintEventHandler(GoPaint);
}
void GoKeyDown(object sender, KeyEventArgs e)
{
if ( e.KeyCode == Keys.Left ) { left = true; }
if ( e.KeyCode == Keys.Right) { right = true; }
if ( e.KeyCode == Keys.Up ) { up = true; }
if ( e.KeyCode == Keys.Down ) { down = true; }
}
void GoKeyUp(object sender, KeyEventArgs e)
{
if ( e.KeyCode == Keys.Left ) { left = false; }
if ( e.KeyCode == Keys.Right) { right = false; }
if ( e.KeyCode == Keys.Up ) { up = false; }
if ( e.KeyCode == Keys.Down ) { down = false; }
}
void GoPaint(object sender, PaintEventArgs e)
{
Image terrain = Image.FromFile(@"object\terrain.bmp");
e.Graphics.DrawImage(terrain, TempMatrixX, TempMatrixY);
Image player = Image.FromFile(@"object\player1.png");
e.Graphics.DrawImage(player , 0, this.Height - 130, 100 , 100);
}
void RefreshTick(object sender, EventArgs e)
{
this.Refresh();
}
void PlayerInfoTick(object sender, EventArgs e)
{
RotatePlayerinfo++;
}
void PlayerMovingTick(object sender, EventArgs e)
{
this.Text="Terrain X:"+TempMatrixX+" Terrain Y:"+TempMatrixY;
if ( TempMatrixX > -1 ) { TempMatrixX = -1; }
if ( TempMatrixY > -1 ) { TempMatrixY = -1; }
if ( up == true ) { TempMatrixY++; }
if ( down == true ) { TempMatrixY--; }
if ( left == true ) { TempMatrixX--; }
if ( right == true ) { TempMatrixX++;}
}
}
}
Can you please help fix this bug. Thx
|
|
|
|
|
Not in the least surprised, to be honest.
Start by not creating huge numbers of Images.
Because you add your handler to teh Paint event:
this.Paint += new PaintEventHandler(GoPaint); Every time you move it will get called. And what does it do?
void GoPaint(object sender, PaintEventArgs e)
{
Image terrain = Image.FromFile(@"object\terrain.bmp");
e.Graphics.DrawImage(terrain, TempMatrixX, TempMatrixY);
Image player = Image.FromFile(@"object\player1.png");
e.Graphics.DrawImage(player , 0, this.Height - 130, 100 , 100);
} Loads two images from files and draws them.
Start by moving those loads out of the paint handler and into the Load event handler via private member variables and use those in your paint event. See what happens.
If that fixes it - and it's quite likely it will - handle the paint event and move your code into that instead of adding a second handler to the chain. It's a lot more obvious to readers what is going on.
And...if that terrain image is the whole background the user is moving across, then I'd strongly suggest you look at redrawing a small part of a move instead of invalidating the whole image and redrawing the lot - it's going to get very slow, very quickly once you have more than one moving object. And it's going to flicker horribly!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
THX, i am fix this problem with partly loading images.
|
|
|
|
|
Hi guys,
I need to write code that verifies an inf and creates a .Cat file something similar to what inf2cat tool does in the WDK.
Does anyone have a clue of which class can accomplish this irrespective of .NET version.
Googled but not much info about this.
Thanks in advance.
|
|
|
|
|
there is nothing in the .Net Framework to do as you suggest - the Windows driver handling 'routines' are at a lower level than than the Framework - so anything available you would have to use P/Invoke to get to it (I am thinking of the setupapi here as the likely candidate)
why are you re-inventing the wheel anyway - if you need to do this from a process, can you not run a process (from System.Diagnostics) to 'spawn' inf2cat & trap/analyse the output ?
if you have no other way, this link alludes to some perl scripts that 'may' if you can find/download them provide a starting point for understanding INF files ChkINF - Windows 10 hardware dev[^] ... all I can say beyond here is 'good luck'
|
|
|
|
|
Thanks for the input and link I was hoping there was an easier way. I might have to stick to P/invoke with this one.
|
|
|
|
|
Is it possible to detect the encoding of each txt file what you import into textBox1.
For example:
If you import a txt file in textBox1 ...
label1.Text = "Windows 1250 - ANSI"; or label1.Text = "Windows 1251 - ANSI" or label1.Text = "UTF-8" ...
If it is possible how to do it, and if it is not possible I apologize. Thank you.
|
|
|
|
|
You might be interested in chardetsharp, which is a .NET port of Mozilla's charset detector.
GitHub - superstrom/chardetsharp[^]
The quick brown ProgramFOX jumps right over the Lazy<Dog> .
|
|
|
|
|
I think that what I wanted was still complicated for me. Thank you.
|
|
|
|
|
|
Code is as following..I am starting some application and triying to write a username into textbox.Unfortunately,FindWindowEx can not get correct handle because target application takes some time to start.How can wait for the application to get correct handle to textbox? WaitForInputIdle doesn't work since program maintains a login window.
Thanks in advance
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint uMsg, IntPtr wParam, string lParam);
const int WM_SETTEXT = 0X000C;
private void button1_Click(object sender, EventArgs e)
{
Process p = Process.Start("SomeApp.exe");
IntPtr AppTextBox = IntPtr.Zero;
int i = 0;
do
{
AppTextBox = FindWindowByCaption(IntPtr.Zero, "SomeApp");
i++;
} while (AppTextBox.ToInt32() == 0);
Thread.Sleep(4000);
AppTextBox = FindWindowEx(p.MainWindowHandle, IntPtr.Zero, "Edit", null);
SendMessage(AppTextBox, WM_SETTEXT, IntPtr.Zero , "Success!");
}
modified 8-Feb-16 16:28pm.
|
|
|
|
|
EDIT:
How are you calling WaitForInputIdle ? You are supposed to supply a milliseconds argument to tell it how long to wait.
What does this loop do?
IntPtr AppTextBox = IntPtr.Zero;
int i = 0;
do
{
AppTextBox = FindWindowByCaption(IntPtr.Zero, "SomeApp");
i++;
} while (AppTextBox.ToInt32() == 0);
The difficult we do right away...
...the impossible takes slightly longer.
modified 8-Feb-16 17:33pm.
|
|
|
|
|
Richard Andrew x64 wrote:
How are you calling WaitForInputIdle ? You are supposed to supply a milliseconds argument to tell it how long to wait.
I know I have to supply a time value in milisecond when using WaitForInputIdle Richard.But I didn't added to code since it doesn't do the job.
Richard Andrew x64 wrote: IntPtr AppTextBox = IntPtr.Zero;
int i = 0;
do
{
AppTextBox = FindWindowByCaption(IntPtr.Zero, "SomeApp");
i++;
} while (AppTextBox.ToInt32() == 0);
With this code above,I tried to wait until SomeApp finished its loading.But this code returns a arbitrary handle and so doesn't work.I thought it may have helped waiting for username login window.
Thank you
|
|
|
|
|