|
I can’t download and use official telegram api in c# to create chat program.
I need steep-by-steep tutorial to do this. And may be one little sample program in c#.
|
|
|
|
|
Sorry but this site does not provide either step by step instructions, or code samples, to order. If you wish to learn this API then go to https://core.telegram.org/[^].
|
|
|
|
|
Hello guys. I took some code from web for running external process in my windows form application. This code contains these lines
process.WaitForExit(10 * 60 * 1000);
Thread.Sleep(200);
try
{
process.Kill();
process.WaitForExit(5000);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
What do these lines of code mean....thanks for any input.
|
|
|
|
|
How about this. Click on the WaitForExit part and hit F1.
Click on Sleep and hit F1.
Click on Kill and hit F1.
Click on WaitForExit and hit F1.
The documentation makes it pretty clear what each of these statements does.
|
|
|
|
|
Downvote countered.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Give a man a fish or teach him to fish.
Apparently, the wrong answer was to teach him to fish.
|
|
|
|
|
I think you're right: he was expecting a whole fish-finger sandwich...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Just to add to what Dave says - if you can't understand (or work out for yourself) what trivial code fragments like that do, I would strongly suggest you stop downloading code from the internet.
If you don't know what code does, you don't know that it (a) does what you want, or (b) does nothing malicious or dangerous.
Would you download an EXE file at random and just run it on your computer? No? So why do the same with code...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
process.WaitForExit(10 * 60 * 1000); --> This starts a wait that remains waiting 10 minuts the exit of the process
Thread.Sleep(200); --> When the wait is finised because the timer expires or the process ends we wait 200 milliseconds
try
{
process.Kill(); --> Try to kill the process manually
process.WaitForExit(5000); --> This wait 5 seconds to check if the process has been killed
}
catch (Exception ex)
{
MessageBox.Show(ex.Message); --> If some problem happen in the try loop it shows the message error using a MessageBox
}
I hope this explanation line by line helps you.
|
|
|
|
|
Hey, Im a C# nooblord. This problem probably has a very easy solution, but im unable tot find out what i did wrong. Could you help me fix it please ? Also could you write the code i need to fix this? Thank you .
http://imgur.com/vqHjMjE[^]
|
|
|
|
|
I guess your intent is to write
if (cislo > nahodne)
instead.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Oh. Thanks
|
|
|
|
|
Screenshot of code are bad form. Not everyone can see the sites you post images to so don't do it.
Copy and paste code into the post and surround the code inside HTML PRE tags.
|
|
|
|
|
That is because the operator > (greater than) cannot be applied to these types. double is a built-in type where as System.Random (class) is a custom type. .NET has no idea how to resolve it.
You wanted to write the condition as,
if(cislo > nahodne) { }
int and double can be somehow checked against each other to resolve the expression.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
In C# assuming I have 2 forms: form1 and form2. I open Form1 drag Statusbar Control into Form1 with the following declaration:
public static void LogStatusBar(string status)
{
try
{
statusBar1.Text = "Thông báo: " + status;
}
catch (Exception ex)
{
}
}
private void form1_Load(object sender, EventArgs e)
{
....
LogStatusBar(Message);
....
}
Form1 run before and open form2, form2 will be used together with function LogStatusBar Form1 (...) I have declared above, and in this form2. I declare the following code:
try
{
....
}
catch (Exception ex)
{
form1.LogStatusBar(ex.Message);
}
My question posed here as Rebuild Solution in statusBar1.Text error will not be public static because of it, according to my understanding of this, verbatim error: Error 1 An object reference is required for the nonstatic field, method, or property 'Vidu.form1.statusBar1'. I want to declare the control statusBar1 was dragging this into the public static Form1 themselves to declare how the band through household property.
|
|
|
|
|
static methods are unrelated to any particular instance of the containing class - so they don't have a this reference to address any non-static class elements (such as field, properties, and methods) with.
Since statusBar will be a class control, it is specific to a particular instance of the containing form, because you will normally have a different status bar for each instance. As a result, you can't access the status bar within any static method.
There are ways round this, but the best is not to try. Instead, create a event in Form2 which Form1 handles, and pass the information either via a propety in teh Form2 instance, or via a custom event args.
See here: Transferring information between two forms, Part 2: Child to Parent[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I am trying to create some CircularStream and / or CircularTextWriter.
When It reach its limit it should continue writing from the start again.
I got 2 problems:
- if I use UTF16 encoding I am not sure whether a given byte is in the middle of a character or not
- even if I use UTF32 I can't cut the stream every 4 bytes as damn unicode characters might need to come in pair sometimes.
basically.. how I like to know... where to split a char[] at a legal place...
[EDIT] kind of fixed...
I create a Stream (view) of the beginning of my CircularStream and read it with Stream Writer and do some educated guess with the StringInfo class
[EDIT2]
Because splitting on char is too hard (2 char might work together depending on the whole line) I decided to split only at line returns!
For the record here is how I read char from the stream:
const int bit00 = 0x00;
const int bit10 = 0x80;
const int bit20 = 0xC0;
const int bit30 = 0xE0;
const int bit40 = 0xF0;
const int bit50 = 0xF8;
const int bit07 = 0x7F;
const int bit06 = 0x3F;
const int bit05 = 0x1F;
const int bit04 = 0x0F;
const int bit03 = 0x07;
public static int ReadUTF8Char(Stream s)
{
int c = s.ReadByte();
if (c == -1)
{
return -1;
}
else if ((c & bit10) == bit00)
{
return c;
}
else if ((c & bit30) == bit20)
{
var c2 = s.ReadByte();
return c & bit05 << 6 | c2 & bit06;
}
else if ((c & bit40) == bit30)
{
var c2 = s.ReadByte();
var c3 = s.ReadByte();
return c & bit04 << 12 | c2 & bit06 << 6 | c3 & bit06;
}
else if ((c & bit50) == bit40)
{
var c2 = s.ReadByte();
var c3 = s.ReadByte();
var c4 = s.ReadByte();
return c & bit03 << 18 | c2 & bit06 << 12 | c3 & bit06 << 6 | c2 & bit06;
}
else
{
return c;
}
}
modified 5-Jun-15 22:22pm.
|
|
|
|
|
The problem is not the writer, but the reader. When reading back you need some way to resynchronise from the middle of a line, to recognise a valid line end. The CR/LF sequence may not be good enough because other UTF sequences could be mistaken for them. Perhaps some other sequence of bytes could be used that cannot be mistaken for anything else.
|
|
|
|
|
In fact you gave me an idea, when the buffer is full and I start overwriting, I can free space until the next line return (which is reasonable it's for program logs, lots of line return).
that's a good work around!
I might do that, since the next alternative I just found:
StringInfo.GetNextTextElement(String, Int32)
needs a String ... whereas I am working with Stream ....
|
|
|
|
|
How about keeping tabs on the byte-offsets of the inserted strings?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
mmm.... I will use a normal TextWriter wrapping an (almost complete now) CircularStream.
there is no really good place for that...
Never mind the CircularStream has a Reclaim delegate property, where I can use a StreamReader on the beginning of the stream, should be acceptable!....
Thanks!
|
|
|
|
|
I have a post from a few days ago mentioning async TCP clients. It has been causing me nothing but trouble.
So i come to you asking what the best method of achieving what i am trying to do is.
I have an unidentified number of clients, sometimes 3 sometimes 5 sometimes 50 that are not all always connected.
The server needs to send information to all of them occasionally. no data needs to be received by the server. It is a very small amount of data that needs to reach all the clients as quickly as possible.
Using Async i keep running into the error "A request to send or receive data was disallowed because the socket is not connected" on the client side after a forced close of the software, or logging off without closing the application properly.
Is there any way to open this connection on demand? Without knowing which clients are online?
|
|
|
|
|
It sounds like you need to use a try/catch block to catch the exception and handle it properly. You can try opening the connection when the error is received.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Good idea, thank you I will let you know how it goes
|
|
|
|