|
livhuone wrote: sofar i cannot retrive it on the pdf controler. please help I'm sorry but you need to give specific details of where in your code the errors occur, and exactly what they are.
|
|
|
|
|
Hello,
I am writing a lengthy list of all of the folders to a List<string>. I am doing that on BackgroundWorker1. I have a second background worker that sleeps for one minute and then starts pulling the information to the list. My problem is that I do not know how to keep the loop going until the List created in the first Background Worker has ended. This is what I have and I know it is wrong.
<pre lang="c#"> private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
{
System.Threading.Thread.Sleep(60000);
int KeepCounting=0;
listBox1.Invoke((Action)(() => listBox1.Items.Add("Starting Scan : " + DateTime.Now.ToString())));
while (KeepCounting < variables.foldersToSearch.Count)
{
listBox1.Invoke((Action)(() => listBox1.Items.Add(variables.foldersToSearch[KeepCounting])));
KeepCounting++;
toolStripStatusLabel1.Text = " Searched " + KeepCounting.ToString() + " folders.";
}
}</pre>
|
|
|
|
|
The biggest problem with doing what you're doing is that List<t> isn't thread safe. You really shouldn't be trying to Add and Remove items from the List<t> without synchronization in place to avoid nasty little bugs that you're going to have a hell of a time reproducing.
Read:
Quote: Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
It is safe to perform multiple read operations on a List<t>, but issues can occur if the collection is modified while it’s being read. To ensure thread safety, lock the collection during a read or write operation. To enable a collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization. For collections with built-in synchronization, see the classes in the System.Collections.Concurrent namespace. For an inherently thread–safe alternative, see the ImmutableList class.
A better alternative would be to use a ConcurrentQueue<t>[^] instead.
|
|
|
|
|
Hi.
I need a tutorial about how to make a Custom Autoupdater cuz i can do 1 by myself :I
no clickonce pls it ins't customizable
someone can help me plz
|
|
|
|
|
The best way for you to tackle this is for you to start defining your requirements. Saying you want an autoupdater is only the start - you need to break that down. For instance, do you want it to be updated from a local network only, or should it be available via the Internet as well? Does the update process require authentication or a license? You need to get a full list of your desired features, and then you start by breaking each part down into manageable tasks.
|
|
|
|
|
|
GuyThiebaut wrote: Here is some codez 4 U 2 look @:
Are you OK? Did you hit your head on something? How many fingers am I holding up ?
|
|
|
|
|
Beeer!
Cue the music to "Our Tune" from Radio 1...
I confess, I am a reformed teenager, a teenager who could not be arsed to spell correctly.
I get triggered every so often when I see a 'plz' and return to my terrible habits.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
im sorry but english is not my native language so in my language (Spanish) "plz" is usually used so i use it just for bad habit.
im quiet new in c# would you pls give me a list of what do i need to define first before all? cuz right now i just want a updater that update my app via Internet and should be licensed
|
|
|
|
|
Member 10928084 wrote: pls give me a list of what do i need to define first before all? To quote Pete "The best way for you to tackle this is for you to start defining your requirements."
Member 10928084 wrote: i just want a updater that update my app via Internet and should be licensed Sure I get that - I think the article will give you everything you need to create an updater that takes update information off an FTP site on the 'internet'.
I don't know what you mean by "should be licensed".
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Hi..
i tried to implement the updater but... i got so many errors and i think that you can help me with this..
this is my patch.cs
http://upaste.me/5604135604bcb815a[^]
the last error that i got was this "the calling thread must be sta because many ui components require this"
can you pls help me with this :S?
|
|
|
|
|
Can I use a .txt file with a delimiter as an input file to a C# program from a network folder? And if so are there any examples of this?
|
|
|
|
|
Yes, you can. It's not that hard.
Normally, this would be a console application and you just use the StandardInput stream like it was a text file. You can get the StandardInput stream by calling Console.OpenStandardInput(). You can send the text file to the application with a simple command line:
C:\>myapp.exe < someTextFile.txt
Simple.
using System;
using System.IO;
namespace StandardInputSnadbox
{
class Program
{
static void Main(string[] args)
{
using (StreamReader inStream = new StreamReader(Console.OpenStandardInput()))
{
while (!inStream.EndOfStream)
{
string inLine = inStream.ReadLine();
Console.WriteLine(inLine);
}
}
}
}
}
|
|
|
|
|
|
a
modified 10-Jul-14 13:22pm.
|
|
|
|
|
I don't see any question here.
Just a code dump...
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
As has been mentioned, there doesn't appear to be any question here - and in the absence of any other explanation, I can only assume you are proud of the code and want to share this with the rest of us.
We have an area for that, but there are rules: posting code with no explanation is not allowed - we need to know what they are, what they do, and how they do it. We also need to know how these are better than the alternatives, and why we would want to use them. A nicely packaged download helps as well.
There are two ways to post such info: as a Tip or an Article.
A Tip is single task focussed; an Article is much more in depth.
This is probably Tip material as it is hard to see how you would get a reasonable article out of stuff that (for the most part) has been covered numerous times.
To try writing this up as a Tip (or an article, but it's less likely to get published) start here: http://www.codeproject.com/script/Articles/Submit.aspx[^]
When you are happy (and it can take a long time to get it right) you can submit it for publication, at which point it enters moderation and is reviewed for quality and acceptability before either being rejected or accepted, either way you will probably get comments on ways to improve it.
But this forum is not the right place!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I have one file xml with one header and n body
<Header>
<C></C>
<D></D>
</Header>
<Body>
<F></F>
</Body>
<Body>
<G></G>
</Body>
<Body>
<H></H>
</Body>
I must create n new file xml with and one For example:
First.xml
<Header>
<B>
<C></C>
<D></D>
</B>
</Header>
<Body>
<F></F>
</Body>
Second.xml
<Header>
<B>
<C></C>
<D></D>
</B>
</Header>
<Body>
<G></G>
</Body>
Third.xml
<Header>
<B>
<C></C>
<D></D>
</B>
</Header>
<Body>
<H></H>
</Body>
Initially I tried to create new n documents equal to the original. After I take First.xml and I keep the first block Body and delete the other Body With Second.xml I keep the second block of the Body and delete the other I also accept any other suggestion.
Thanks
modified 9-Jul-14 5:06am.
|
|
|
|
|
You just need to create a new file for each <Body> element in the original. Since each has the same header section it should be fairly easy to figure it out. Assuming you are using the XMLDocument[^] class in all cases.
|
|
|
|
|
Linq to XML[^] makes this fairly simple:
XDocument document = XDocument.Parse(@"<root>
<Header>
<B>
<C></C>
<D></D>
</B>
</Header>
<Body>
<F></F>
</Body>
<Body>
<G></G>
</Body>
<Body>
<H></H>
</Body>
</root>");
XName rootName = document.Root.Name;
XDeclaration declaration = document.Declaration;
XElement header = document.Root.Element("Header");
IEnumerable<XDocument> newDocuments = document.Root.Elements("Body")
.Select(body => new XDocument(
declaration,
new XElement(rootName,
header,
body
)
));
foreach (XDocument newDocument in newDocuments)
{
Console.WriteLine(newDocument);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i'am want to encrypt and decrypt text in textboxt.text in second form but what to adding the code, this is the code. thanks
Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
namespace Rc5_v2
{
static class Program
{
/// summary
/// The main entry point for the application.
/// summary
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main_form());
}
}
}
RC5.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Net.Mail;
using System.Net.Mime;
using System.Text.RegularExpressions;
using System.Web;
namespace Rc5_v2
{
class Rc5
{
uint[] s;
uint[] l;
uint b, u, t, c;
byte[] key;
int rounds;
public Rc5()
{
string str = "ModifyRC5";
key = GetKeyFromString(str);
rounds = 16;
b = (uint)key.Length;
u = 4;
t = (uint)(34);
c = 12 / u;
s = new uint[34];
l = new uint[12];
GenerateKey(key, rounds);
}
public Rc5(string password,int round)
{
key = GetKeyFromString(password);
rounds = round;
b = (uint)key.Length;
u = 4;
t = (uint)(2 * rounds + 2);
c = Math.Max(b, 1) / u;
s = new uint[2 * rounds + 2];
l = new uint[key.Length];
GenerateKey(key, rounds);
}
public Rc5(byte[] password, int round)
{
rounds = round;
key = password;
b = (uint)password.Length;
u = 4;
t = (uint)(2 * rounds + 2);
c = Math.Max(b, 1) / u;
s = new uint[2 * rounds + 2];
l = new uint[password.Length];
GenerateKey(key, rounds);
}
//to circulate int left
private uint leftRotate(uint x, int offset)
{
uint t1, t2;
t1 = x &gt;&gt; (32 - offset);
t2 = x &lt;&lt; offset;
return t1 | t2;
}
//to circulate int right
private uint RightRotate(uint x, int offset)
{
uint t1, t2;
t1 = x &lt;&lt; (32 - offset);
t2 = x &gt;&gt; offset;
return t1 | t2;
}
//encryption operation on two block
private void Encode(ref uint r1, ref uint r2, int rounds)
{
r1 = r1 + s[0];
r2 = r2 + s[1];
for (int i = 1; i &lt;= rounds; i++)
{
r1 = leftRotate(r1 ^ r2, (int)r2) + s[2 * i];
r2 = leftRotate(r2 ^ r1, (int)r1) + s[2 * i + 1];
}
}
//decryption operation on two block
private void Decode(ref uint r1, ref uint r2, int rounds)
{
for (int i = rounds; i &gt;= 1; i--)
{
r2 = (RightRotate(r2 - s[2 * i + 1], (int)r1)) ^ r1;
r1 = (RightRotate(r1 - s[2 * i], (int)r2)) ^ r2;
}
r2 = r2 - s[1];
r1 = r1 - s[0];
}
private void GenerateKey(byte[] key, int rounds)
{
uint P32 = uint.Parse("b7e15163", System.Globalization.NumberStyles.HexNumber);
uint Q32 = uint.Parse("9e3779b9", System.Globalization.NumberStyles.HexNumber);
for (int i = key.Length - 1; i &gt;= 0; i--)
{
l[i] = leftRotate((uint)i, 8) + key[i];
}
s[0] = P32;
for (int i = 1; i &lt;= t - 1; i++)
{
s[i] = s[i - 1] + Q32;
}
uint ii, jj;
ii = jj = 0;
uint x, y;
x = y = 0;
uint v = 3 * Math.Max(t, c);
//mixing key arrayes
for (int counter = 0; counter &lt;= v; counter++)
{
x = s[ii] = leftRotate((s[ii] + x + y), 3);
y = l[jj] = leftRotate((l[jj] + x + y), (int)(x + y));
ii = (ii + 1) % t;
jj = (jj + 1) % c;
}
}
//convert key from string to byte array
private byte[] GetKeyFromString(string str)
{
char[] mykeyinchar = str.ToCharArray();
byte[] mykeyinbytes = new byte[mykeyinchar.Length];
for (int i = 0; i &lt; mykeyinchar.Length; i++)
{
mykeyinbytes[i] = (byte)mykeyinchar[i];
}
return mykeyinbytes;
}
public void Encrypt(FileStream streamreader,FileStream streamwriter)
{
uint r1, r2;
System.IO.BinaryReader br = new System.IO.BinaryReader(streamreader);
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(streamwriter);
long filelength = streamreader.Length;
while (filelength &gt; 0)
{
try
{
r1 = br.ReadUInt32();
try
{
r2 = br.ReadUInt32();
}
catch
{
r2 = 0;
}
}
catch
{
r1 = r2 = 0;
}
Encode(ref r1, ref r2, rounds);
bw.Write(r1);
bw.Write(r2);
filelength -= 8;
}
streamreader.Close();
streamwriter.Close();
}
public void Decrypt(FileStream streamreader,FileStream streamwriter)
{
uint r1, r2;
System.IO.BinaryReader br = new System.IO.BinaryReader(streamreader);
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(streamwriter);
long filelength = streamreader.Length;
while (filelength &gt; 0)
{
try
{
r1 = br.ReadUInt32();
r2 = br.ReadUInt32();
Decode(ref r1, ref r2, rounds);
if (!(r1 == 0 &amp;&amp; r2 == 0 &amp;&amp; (filelength - 8 &lt;= 0)))
{
bw.Write(r1);
bw.Write(r2);
}
if (r2 == 0 &amp;&amp; (filelength - 8 &lt;= 0))
{
bw.Write(r1);
}
filelength -= 8;
}
catch
{
System.Windows.Forms.MessageBox.Show("May be U try to decrypt an normal file (plain file)", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
return;
}
}
streamreader.Close();
streamwriter.Close();
}
}
}
Form4.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net;
namespace Rc5_v2
{
public partial class Form4 : Form
{
SmtpClient obj_SMTPClient;
MailMessage Obj_MailMsg;
Attachment obj_Attachment;
//int rounds01;
//string fileName01;
//string saveFileName01;
//string password01;
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog() == DialogResult.OK)
{
label3.Text = open.FileName;
}
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
{
MessageBox.Show("Please require, column must be content !!!");
}
else
try
{
obj_SMTPClient = new SmtpClient("smtp.gmail.com");
Obj_MailMsg = new MailMessage();
obj_Attachment = new System.Net.Mail.Attachment(label3.Text);
Obj_MailMsg.From = new MailAddress(textBox1.Text);
Obj_MailMsg.To.Add(textBox3.Text);
Obj_MailMsg.Body = textBox5.Text;
Obj_MailMsg.Attachments.Add(obj_Attachment);
Obj_MailMsg.Subject = textBox4.Text;
SmtpClient smtps = new SmtpClient("smtp.gmail.com", 587);
obj_SMTPClient.Credentials = new NetworkCredential();
obj_SMTPClient.Port = 587;
obj_SMTPClient.Credentials = new System.Net.NetworkCredential(textBox1.Text, textBox2.Text);
obj_SMTPClient.EnableSsl = true;
obj_SMTPClient.Send(Obj_MailMsg);
obj_SMTPClient.EnableSsl = true;
obj_SMTPClient.Send(Obj_MailMsg);
MessageBox.Show("Message Successful!!!");
}
catch
{
MessageBox.Show("Request TimeOut!!!");
}
}
private void button4_Click(object sender, EventArgs e)
{
foreach (Control sayre in this.Controls)
{
if (sayre is TextBox)
{
(sayre as TextBox).Clear();
}
}
}
private void button8_Click(object sender, EventArgs e)
{
foreach (Control sayre in this.Controls)
{
if (sayre is TextBox)
{
(sayre as TextBox).Clear();
}
}
}
private void Encrypt_Click(object sender, EventArgs e)
{
}
private void Decrypt_Click(object sender, EventArgs e)
{
}
}
}
modified 9-Jul-14 20:03pm.
|
|
|
|
|
I am not wading through a large, unformatted pile of "code" looking for what you want me to help you with.
Edit your question, format the code using <pre> tags to preserve the formatting, and remove anything I don't need to help with your problem. Then, explain exactly what problem you have, and what help you need - remembering that we can't see your screen, access your HDD, or read your mind.
Help us to help you!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Yes and ofcourse but i'am want to encrypt and decrypt some string in textboxt not other. thanks
|
|
|
|
|
...but you couldn't be bothered to read what I wrote and actually do anything?
Why, pray, would I want to help you if you can't be bothered to help me to do it?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
thanks for the answer, i will try in my own
|
|
|
|
|