|
You're welcome
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In MSDN Application.Idle Event (System.Windows.Forms)[^] one can read concerning using Application.Idle in the paragraph Remarks:
Quote: Caution
Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
When an Application is disposed, does it not also mean the app exits? And therefore all objects will be finalized? So I don't see why/where a Memory leak can result...
I don't get the point on the above MSDN description. Can you help me on this?
Thank you in advance.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
A thread is not an application: if you start a console app, then you don't create an Application object, you only do that for Windows apps.
And processing can continue once the Application object is closed - have a look at programs.cs and you will see:
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMain());
}
}
It is perfectly possible to add code after the Application.Run hass completed, so unless you manually detach your event handler from the static Idle event the Application object and everything it contains can't be disposed.
If you attach to it, you should detach as well just in case of later changes.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thank you very much for your reply
Yes in case one adds code after Application.Run then it makes sense.
Finally this has completely convinced me to do it:
Quote: If you attach to it, you should detach as well just in case of later changes.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Hi,
Is it possible to convert a .wmf file to Base64String?
Thanks
|
|
|
|
|
Yes: all files are just a stream of byte values - it's the interpretation that software puts on the internal format of those bytes that makes it a "WMF" or "JPG" file. The extension just indicates what format the software should look for.
string base64 = Convert.ToBase64String(file.ReadAllBytes(@"D:\Temp\myPicture.wmf")); However, that doesn't mean that whatever you pass the base64 string to can do anything useful with it. For example, not all browsers support WMF file data in any format, and changing it to Base64 will not fix that. WMF is pretty much a "Windows only" image format: you would probably be better off using a more generic format such as JPG, GIF, or PNG.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
wow! that's just in one line!!!
Thanks very much!
How do I load it back to a form? 
|
|
|
|
|
|
Thanks! 
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I more concern.
I want the metafile to be created in memory rather than saving to a disk. It should be a blank metafile. I assume it is like this.
metfile = New Metafile(hdc, EmfType.EmfPlusDual)
|
|
|
|
|
Hi,
I have a web service which returns JSON string like this:
{
"valid": true,
"messages": [
"Cannot validate bank code length. No information available.",
"Cannot get BIC. No information available."
],
"iban": "BH00000000000000000000",
"bankData": {
"bankCode": "",
"name": ""
},
"checkResults": {
"bankCode": false
}
}
I am able to get it using below code:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://openiban.com/validate/" + txtIBAN.Text.Trim());
try
{
WebResponse response = request.GetResponse();
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
string strsb = reader.ReadToEnd();
}
}
catch (WebException ex)
{
WebResponse errorResponse = ex.Response;
using (Stream responseStream = errorResponse.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
String errorText = reader.ReadToEnd();
}
throw;
}
but I want to know can I now read the value valid if it's rue or false?
Thanks,
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
Use Json.NET[^] - you can add a reference via NuGet[^]:
Install-Package Newtonsoft.Json
You can then either use LINQ to JSON[^] to read the property:
JObject result = JObject.Parse(strsb);
bool isValid = (bool)result["valid"];
or create strongly typed classes to represent the result:
public class ResponseData
{
public bool valid { get; set; }
public IList<string> messages { get; set; }
public string iban { get; set; }
public BankData bankData { get; set; }
public IDictionary<string, bool> checkResults { get; set; }
}
public class BankData
{
public string bankCode { get; set; }
public string name { get; set; }
}
...
var result = JsonConvert.DeserializeObject<ResponseData>(strsb);
bool isValid = result.valid;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
To add to Richard's answer, you can use this free handy-dandy online tool to generate C# classes from JSON. You may want to rename the generated class names to be more developer friendly.
json2csharp - generate c# classes from json[^]
/ravi
|
|
|
|
|
|
When I look at the message text above, I think you can get confused by their convention. Their "valid": true seems to mean that the message you sent them was syntactically correct. But you are likely interested in the IBAN. And that's given in a different part of the message: "checkResults": { "bankCode": false } .
Well, I tried that service with my IBAN, and got following result (I edited the number on the response below):
{
"valid": true,
"messages": [],
"iban": "DE...........",
"bankData": {
"bankCode": "",
"name": ""
},
"checkResults": {}
} WTF... A valid IBAN is indicated by an empty checkresult and an empty messages array.
|
|
|
|
|
Respected sir /madam
good morning i want to send hindi sms from computer to mobile using asp.net c#.kindly send me hindi sms application code
thanks
|
|
|
|
|
No there is no Add to cart here...
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Hindi SMSes would be sent as a Unicode SMS (UCS2 encoding). If you have a basic SMS sending package, see 3GPP TS 23.038 (available for free at www.3gpp.org[^]) for the details that must be changed in the SMS fragment's header.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
modified 28-Jul-16 3:08am.
|
|
|
|
|
Is there a way to accomplish that a sequence of code does run exclusively, I mean no Task scheduling allowed while executing the sequence?
The reason behind it is, I try to determine the memory usage of a class this way:
private void MemoryTest()
{
const int cTestObjCount= 10000;
long before= GC.GetTotalMemory(false);
string[] stringArray= new string[cTestObjCount];
long after= GC.GetTotalMemory(false);
}
Or does somebody knows a better method how to determine the memory consumption of a class (without the help of a profiler)?
Thank you in advance.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
There is no way to prevent this in the .NET framework. Thread switching is in the control of the OS.
This space for rent
|
|
|
|
|
Thank you very much again for your help.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
The only reliable way would be to use a memory profiler. Either CLR Profiler[^] or PerfView[^] should do the job.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you for this, I allready know it.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Error :The type or namespace name 'Contract_Kind' could not be found (are you missing a using directive or an assembly reference?)
///
/// Gathers values from contract kind checkboxes (Forex, Equity, Options)
///
private IEnumerable<contractkind> GetSelectedContractKinds()
{
if (chbFutures.Checked)
{
yield return Contract_Kind.Future;
yield return Contract_Kind.FutureCompound;
yield return Contract_Kind.GenericCompound;
}
if (chbForex.Checked)
{
yield return Contract_Kind.Forex;
}
}
}
Can somebody help me to fix this ERROR.
David
|
|
|
|