|
I would organize things a bit differently:
1) simple scheme
1A. have your PenDriveBackupForm as it is, however without the BackgroundWorker, as it does not belong to the form.
1B. have your RecursiveCopy class, with a constructor that creates a single (and private) BackgroundWorker (with the "new" keyword), to be used inside that class only; and give it a Label parameter, which you store in a private class member, so the BGW inside that class can access it.
2) better scheme (more object-oriented; keywords are: delegate, event)
2A. same as 1A.
2B. have your RecursiveCopy class, with a constructor that creates a single (and private) BackgroundWorker, to be used inside that class only; don't give it a Label parameter; give the class a public event of type Action<string> which almost means "function pointer to a function that takes a string and returns nothing". Now let your BGW fire that event.
2C. Add a "SetProgressLabel()" method to PenDriveBackupForm to accept a string and set the Label; then also add a delegate for that method to the public event you provided in RecursiveCopy.
The net result is: RecursiveCopy will execute a method of which it does not know much, and SetProgressLabel() will be called when necessary; the coupling between both classes is minimal, you can change the Label to something else without telling RecursiveCopy at all (which can't be done in the simple scheme).
modified on Monday, December 14, 2009 7:35 PM
|
|
|
|
|
Using SMO with SQL Express 2005, I'm experiencing some frustrating behavior.
I'm using SMO Server and Database classes to script my database using Database.ExecuteNonQuery . The database objects are getting scripted correctly, but I'm having problems re-connecting to the database (using SqlConnection.Open ). I get a SqlException ("System.Data.SqlClient.SqlException: Cannot open database \"MyDatabase\" requested by the login. The login failed.\r\nLogin failed for user 'MyDomain\\MyUser'.\r\n at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)\r\n at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)\r\n at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)\r\n at System.Data.SqlClient.SqlConnection.Open()\r\n at MyCodePath\\DataAccessFactory.cs:line 57")
The problem "goes away" if I just wait before trying to create the second connection e.g. if I use a breakpoint and step through the code it works fine.
I am closing my previous connection (the one where I scripted the database) and everything is sequential on a single (the UI) thread.
I'd hate to have to code some delay or retry logic for something that seems pretty standard.
|
|
|
|
|
It's normal, you may use a connection pool in order to avoid problems of connection.
myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=MyDatabase;server=MyServer;Connect Timeout=30";
The value is expressed in seconds:
Connect Timeout=30
|
|
|
|
|
That's kind of annoying. I've noticed these types of subtleties even when using standard MS tools like SSMS. My first reaction when something fails is to change some variable of the experiment before trying again, but with SQL Server, a lot of times, you just need to act like a crazy person and try the EXACT same thing expecting different results.
Thanks for your tip, I had managed to workaround the issue, but I might implement this suggestion as well.
|
|
|
|
|
greetings,
for the first time ever im investigating RichTextBox control in C# windows forms. i know i need this control in my app as textBox is to simple for my needs.
i have the followig code:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace _19_richtextbox<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void richTextBoxHome_KeyDown(object sender, KeyEventArgs e)<br />
{<br />
if (e.KeyValue == (char)(Keys.Return))<br />
{<br />
richTextBoxChat.AppendText("Home:" + richTextBoxHome.Text + "\n");<br />
richTextBoxHome.Clear();<br />
}<br />
}<br />
<br />
}<br />
}<br />
for the moment i just want whatever is typed in one richtextbox to be displayed on the other richtextbox on hitting return.
the issue is everytime i hit return the data is being transfered to the other control but the first control is left with a carriage return before the cursor. this happens everytime i hit return.
how do i make it stop doing this?
both the controls accept multiline input.
please advise if i need to provide more info.
thank you for your time.
|
|
|
|
|
If you handle the return key and don't tell the OS you have done it, it passes it through to the default handler afterwards. Add "e.Handled = true;" to your code, all will be fine.
[edit]I can't spell "the" correctly - fixed.[/edit]
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
thank you for your response. it has solved my problem.
may i introduce you to my new situation?
i would like a way to make the "Home:" part in bold.
i have found very little info on this on my searches. the following are the only actual code that i could understand.
rtb1.Rtf = @"{\rtf1\ansi {\b hello} {\i World}}" ;
richTextBox1.Rtf = @"{\rtf1\ansi This is in \b bold\b0.}";
-----------
im not sure how to proceed with this info. i just want the richtextbox to display "Home:" and "Away:" in bold and be able to handle URLs in text.
please advise what should i specify when searching this potic on google or any reference your could think of would be of great help.
|
|
|
|
|
You seem to have most of what you need there already, but have a look at this[^] - it's in VB, but it's pretty clear.
Just think of rtf as an unreadable HTML file and you are just about there!
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
|
Hi
Am i ask a hard question about 4hours ago.
|
|
|
|
|
Your question is indeed tough. You have to wait patiently for an answer by somebody who knows the answer.
|
|
|
|
|
The reason you did not get an answer is because
a) It was a repost.
b) Your original was replied to, and you reposted last time
http://www.codeproject.com/Messages/3302834/Re-backup-database.aspx[^]
c) There are many examples on CP about to achieve what you want to achieve.
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
My question was changed.
I asked that how can i backup from database.
I got my answer and check it when my database attach to microsoft sql.
but it is necessary for me to use SQLEXPRESS and that way doesn't work when i add my database to SQLEXPRESS and detach from microsoft sql.
I explain more about 4 hours ago.
If somebody know the answer please help me.
|
|
|
|
|
Does shouting and hassling people work in your company? Because in all the ones I've worked in, it just gets peoples backs up, and (certainly with me) reduces the amount of help given to the minimum they can get away with. Just thought I'd mention it...
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
please !
I don't think that i'm shouting or... .
I thought that i used wrong sentence or wrong structure because my first language is not english.
but if i told in bad way , i'm sorry.
|
|
|
|
|
using UPPER-CASE is equivalent to shouting.
|
|
|
|
|
REALLY? I WAS WONDERING WHY MY FRIENDS WENT DEAF WHEN I TURNED MY SCREEN-READER ON
[edit] Never mind, that sounded funnier in my mind.
modified on Monday, December 14, 2009 3:58 PM
|
|
|
|
|
|
Hello,
I'd like to create an array, and have it contain two items (two-dimensional) of two different types.
I believe the best way to do this is create my own type, however, I'm unsure how to handle the need for an array.
For instance, I want to create something that will take in:
SnapShot[i] = ( DateTime DateTime.Now, Int Size );
How can this be done?
Thanks,
Matt
|
|
|
|
|
Why not use a Dictionary?[^]
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Thanks!
This will work for two items.
What can I do if I want to store more items?
Thanks,
Matt
|
|
|
|
|
Then I would create a class to hold the info, and either use a Dictionary or hold it in a List<T>. You get the flexibility of the array, but without the need to specify the initial size .
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
I'd suggest creating a SnapShotInformation class with Date and Size properties.
You can then maintain a List<SnapShotInformation> . This has the advantage of being more maintainable and the size of the list is dynamic (ie you can add more items to is and it will resize).
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
why Class? Shouldn't struct be enough?
I Would use struct instead class. Because you do not need to hold any Function only data
|
|
|
|
|
Saksida Bojan wrote: I Would use struct instead class. Because you do not need to hold any Function only data
It is correct in C++ but not in C#. A struct in C++ is mainly used for POD types and in C#, you hardly write structs. You write it only when you need value semantics or you need to communicate with legacy APIs.
Best wishes,
Navaneeth
|
|
|
|