compact-framework

Function that creates a timestamp in c#

梦想与她 提交于 2019-11-27 06:13:28
I was wondering, is there a way to create a timestamp in c# from a datetime? I need a millisecond precision value that also works in Compact Framework(saying that since DateTime.ToBinary() does not exist in CF). My problem is that i want to store this value in a database agnostic way so i can sortby it later and find out which value is greater from another etc. I always use something like the following: public static String GetTimestamp(this DateTime value) { return value.ToString("yyyyMMddHHmmssfff"); } This will give you a string like 200905211035131468, as the string goes from highest order

How do I GetCustomAttributes?

强颜欢笑 提交于 2019-11-27 03:11:19
问题 I have tried the following code using the 2.0 framework and I get an attribute back, but when I try this on the compact framework, it always returns an empty array. The MSDN documenation says its supported, am I doing something wrong? Test x = new Test(); FieldInfo field_info = x.GetType().GetField("ArrayShorts"); object[] custom_attributes = field_info.GetCustomAttributes(typeof(MarshalAsAttribute), false); [StructLayout(LayoutKind.Sequential)] public struct Test { [MarshalAs(UnmanagedType

What's the best way to enter numbers in Windows Mobile? (.NET CF 3.5)

被刻印的时光 ゝ 提交于 2019-11-27 02:59:27
问题 There must be a better way than a constrained numeric updown control. 回答1: The easiest way to enter numbers (especially non-integer numbers) in Windows Mobile (or in a regular Windows application) is to just have a text box that the users type into, and then validate that they've entered a proper number. The problem with this approach in Windows Mobile is that the default SIP (Soft Input Panel aka little pop-up keyboard) looks like this: alt text http://img510.imageshack.us/img510/6210/sipreg

Serial Port ReadLine vs ReadExisting or how to read the data from serial port properly

六月ゝ 毕业季﹏ 提交于 2019-11-27 02:41:09
问题 I am reading data from serial port. The data comes off the scale. I am now using Readline() and getting data dropped even after I removed DiscardInBuffer() . What is the proper way to read the data from the serial port? There are so few examples online that I feel it's like some holy grail that no one has figured out. Any help please? Seems like serial port is a capricious child. C#, WinCE 5.0, HP thin client, Compact framework 2.0 private void WeighSample() { this._processingDone = false;

How to get the path of app(without app.exe)?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 02:22:10
问题 I want to get the path of my app like: "\\ProgramFiles\\myApp", I try to use the following code: string path = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase; But it returns a path which has "\\myapp.exe" at the end. I also tried: string path = System.IO.Directory.GetCurrentDirectory(); But it throws an “NotSupportedException”. Is there any way to get a path without .exe at the end? 回答1: path = System.IO.Path.GetDirectoryName( path ); 回答2: Application.StartupPath should

How can I create an instance of an arbitrary Array type at runtime?

陌路散爱 提交于 2019-11-27 02:13:59
I'm trying to deserialize an array of an type unknown at compile time. At runtime I've discovered the type, but I don't know how to create an instance. Something like: Object o = Activator.CreateInstance(type); which doesn't work because there is no parameterless constructor, Array doesn't seem to have any constructor. Use Array.CreateInstance . You can use one of Array's CreateInstance overloads e.g.:- object o = Array.CreateInstance(type, 10); Quite an old post, but while answering a new question, though of posting a related example of creating a multi-dimensional array. Assuming the type (

Reading file content to string in .Net Compact Framework

落爺英雄遲暮 提交于 2019-11-27 01:44:31
问题 I am developing an application for mobile devices with the .net compact framework 2.0. I am trying to load a file's content to a string object, but somehow I can't get it done. There is no ReadToEnd() method in the System.IO.StreamReader class. Is there another class that provides this functionality? 回答1: StringBuilder sb = new StringBuilder(); using (StreamReader sr = new StreamReader("TestFile.txt")) { String line; // Read and display lines from the file until the end of // the file is

How to get exe application name and version in C# Compact Framework

半世苍凉 提交于 2019-11-27 01:15:04
问题 My application has an exe and uses some DLLs. I am writing all in C#. In one DLL I want to write a method to get the application name and version from the version information in the exe. I understand that in full .NET I could use GetEntryAssembly, but that that is unavailable in CF. 回答1: Getting the app name: System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; Getting the version: System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; You might want to use

Partly crashing application? How can I catch uncatchable exceptions?

巧了我就是萌 提交于 2019-11-26 23:35:14
问题 I have a program written in C#, running on a Windows CE device (on Compact Framework). It processes minimal user actions (button clicks), uses serial port and TCP/IP communication. The problem is sometimes the software shuts down on its own. In the background the application (or parts of the application) seems to be still running (at least in one documented case it was) because it uses the serial port, so restarting the application doesn't help. I can't reproduce the problem since it happens

Uri.EscapeDataString() - Invalid URI: The Uri string is too long

元气小坏坏 提交于 2019-11-26 23:34:05
问题 I'm using compact framework/C# on windows mobile. In my application I am uploading data to the server by serializing objects and using a HttpWebRequest/POST request to send the information up. On the server the post data is de-serialised and saved to the db. The other day I realised that I had a problem with special characters in the post data (ampersands etc..). So I introduced Uri.EscapeDataString() into the method and all was well. However, today I have discovered that there is a problem