|
I used the patches: from 20+ a day.
It wasn't easy, but it got easier - and I'm glad I did kick 'em in the end.
But I do know this: the only way to quit is to want to quit more than you want to smoke. If you don't have better mental reasons for quitting than you do for continuing then you won't stop - the real battle isn't the nicotine addiction (though that is pretty rough) it's the mental habit of smoking and the association of smoking with places and actions. So if you smoke when you drink beer - stop drinking beer for a few weeks; drink wine instead and don't create an association between wine and smoking.
"Wanting to quit" is what got me off drinking, smoking and several illegal narcotics...
Haven't found anything that makes me "want" to give up motorcycles or coffee though!
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 – ∞)
|
|
|
|
|
|
You can use a database and store your data in a table and generate a unique key to identify the data and pass this key in the url query string. On the target page, extract the key and query the database to get the data.
Sharath Surendran wrote: <layer>is there a way we can send objects across the webpages. Yes, serialize the object and use the same technique stated above.
|
|
|
|
|
|
|
|
I have one requirement , I have a gridview where i will load details of some ip address with its credential. Currently i will perform task related to ip adresses one by one. but now we have a requirement to speed up the process. Now i want to do the task parallely. I can use multithreading and start the threads and join them but the issue is i want to process only 2 set of ip i.e threads at one given point of time.So once these two threads complete the next set of two ips from gridview should be processed parallely.is it possible using multithreading .
|
|
|
|
|
Yes, here's how I would do it:
When the user tells the program to start, add all the IP's to a Queue<string>[^]. Then create two background workers[^].
Give each background worker one of the IP's and remove them from the queue. When the background worker completes, save the data and give it another IP from the queue (remove it when done). Keep doing this for each background worker until the queue is empty.
|
|
|
|
|
can we do it using Thread class
|
|
|
|
|
Yes.
BackgroundWorker is just a wrapper for the Thread class, with progress reporting added in. It's easier to use, but it creates Thread instances for you, is all.
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 – ∞)
|
|
|
|
|
In short the answer is no - multi threading is not the same as parallel processing.
One thing to bear in mind is if you do decide to dive into parallel processing what is your strategy for conflicts when two processes need to update the same data at the same time?
Probably the simplest and cheapest method is to up the RAM, on the computer running this application, and index any tables that are used in any background databases.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
On a single core machine I would agree with you, but those are not common these days. Threading done correctly is parallel programming and there are very easy ways to deal with resource contention. Many .NET BCL collections are atomic (thread safe), he could just store the results in there while running multiple threads and update the UI based on one way bindings.
Even the .NET TPL runs on a single machine, maybe you are thinking of distributed processing? He doesn't say that this is a RAM intensive or database application, its a network one that takes some time to gather information about network resources so I'm a little confused about your comment on RAM or database operations...
|
|
|
|
|
I read that he is using a datagrid and this led me to believe that may be using a database to populate the datagrid.
He doesn't state what the source of the datagrid is, only the contents.
He then mentions that he need to run two processes in parallel I understood that he wants to literally run two processes at the same time(that's what parallel means to me) - based on my understanding of threading this is not guaranteed by threading processes.
Hence my suggestion for more RAM to which could speed up bottlenecks in processing time and indexes based on my assumption with regards to the datagrid.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Ooh, I just refreshed myself on looked at this .NET TPL[^] I stand corrected regarding threading...
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
If the operation he were conducting were processor/memory intensive I would agree that threading may not solve his issue, but with network operations most of the time is spent with the socket in a wait state (sending or receiving), which frees up more threads to get into the wait state or do other work. Since data may arrive from a thread started later than an earlier one, threading and tasks really do behave as if they operate in parallel, even on a single core processor.
The TPL was a major change to the .NET framework, which is why .NET 4 is an entire new runtime than 3/3.5 which runs on/are extensions to the 2.0 runtime.
|
|
|
|
|
<pre lang="text"> Hi there,
I am attempting to write a program which adds up the values in a 2D array to determine if the array is a magic square(that is, that all rows, all columns, and all diagonals add up to the same amount). As you can see I have not gotten very far, and am having trouble working out how to add up each separate row and store the values as separate variables , so I can compare them.
I would appretiate some help on this if possible.
private void RunQuestionFour()
{
int[,] anArray;
int columns;
int rows;
int tempTotalvalue = 0;
Random rndNumber1 = new Random();
Console.WriteLine("Please enter an integer to determine the size of the array e.g 5 = 5x5");
columns = Convert.ToInt16(Console.ReadLine());
rows = columns;
Console.WriteLine("\n");
anArray = new int[rows,columns];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
int random1 = rndNumber1.Next(1, columns + 1);
anArray[i, j] = random1;
Console.Write("{0} ", anArray[i, j]);
}
Console.WriteLine();
}
for (int y = 0; y < rows; y++)
{
tempTotalvalue = 0;
for (int x = 0; x < columns; x++)
{
tempTotalvalue = tempTotalvalue + anArray[y, x];
}
Console.WriteLine(tempTotalvalue);
}
Console.ReadLine();
}
static void Main(string[] args)
{
Soft140 mySoft140 = new Soft140();
mySoft140.RunProgram();
Console.ReadKey();
}
}
}
|
|
|
|
|
|
It's not complicated: you don't need to store values, you just need to know if they are the same as each other.
So, start with moving your temporary value outside the rows loop:
int matchThis = -1;
for (int y = 0; y < rows; y++)
{
tempTotalvalue = 0;
for (int x = 0; x < columns; x++)
{
tempTotalvalue += anArray[y, x];
}
if (matchThis >= 0 && matchThis != tempTotalvalue)
{
Console.WriteLine("Not a magic square");
return;
}
matchThis = tempTotalvalue;
}
Console.WriteLine("Rows OK");
You can do much the same for the Columns (you can keep the existing value of matchThis - but the diagonals are slightly more of a problem! (There is a trick you can use though: look at the % operator - hint, hint)
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 – ∞)
|
|
|
|
|
You do realize that if you generate a #Nx#N matrix of random numbers the chance the result will satisfy the conditions for being a magic square are very low ... and, that as the size of the matrix increases, the chances get exponentially less and less ?
For validating whether your #Nx#N matrix is a magic square: traversing it using for-loops is quite straightforward, if tedious, but it's a good exercise to improve your mastery of for-loops to implement, I think. If you are new to C#, you might benefit from actually writing out the series of for-loop indexes you require for each test case (rows, columns, right-left diagonal, left-right diagonal).
If you are studying Linq and switch to using something like a List<List<int>> to hold your matrix, then Linq's operators like 'Sum can make validation much easier.
private bool testMagic(List<List<int>> testSquare)
{
int firstRowSum = testSquare[0].Sum();
for (int i = 1; i < magicNSides; i++)
{
if (testSquare[i].Sum() != firstRowSum) return false;
}
return true;
} For testing the Rows using Linq it can be even simpler:
bool IsMagicRows = squareList.All(x => (x.Sum() == firstRowSum)); Whichever strategy you use, validation in this case, imho, is best done in a way where you do a series of tests, and stop testing the moment any one of them fails.
For example, if you calculate the sum of the items on the first row of your array (or in the first List<string> inside your List<List<int>>) then you can start testing the other rows and stop immediately if any row does not have a sum equal to the sum of the first row.
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
modified 20-Jan-14 15:24pm.
|
|
|
|
|
Hello, I have created a class to read an xml file, which contains 5 different list of tables. Therefore I have 5 different custom lists
List<listtables1>, List<listtables2> etc..
I would like to create a function to process any one of the 5 lists based on the user type.
Any ideas what is the best way to achieve this, instead of creating 5 different functions?
private void ProcessTableList()
{
// Need to declare a variable of type depending on user type
e.g. List<listtables1> customList = new List<listtables1>
for(int i=0; customList.countl i++)
{
//do something
}
}
.
modified 20-Jan-14 9:23am.
|
|
|
|
|
Sounds to me you'd want to use a Generic Method[^].
Cheers!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
This is ASP.NET ? or Win Forms ? or ... ?
What are the underlying Types of the Tables; are they DataSets ?
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
Depending on what the lists contain (any common data members) and what you need to do to them, you might consider using a common base class or an interface. You would then have 5 lists of that base class or interface and pass each one to the same function. As long as you only need to execute common functionality for all lists it should work.
If you need special functionality for some ofthe lists, you could either insert an if like
if (item is listtables1)
{
listtables1 tmp = (listtables1) item;
}
into the common function.
Or you use a different approach: You keep the lists of the special types and create a special function for each type that needs special handling. Then you can call the common function from the special functions passing the base class/interface of the current item. Or you call the common function directly in a loop for the classes without special handling.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Dear All,
i m new to VS2010, but i know some basic ,
my requirement is to connect oracle database using C#,
and i m able to do that,
i m want to do using with 3/4 tier archi.
just i know the connection string and database connectivity.
how to make my DAL class for oracle ...
any example would be appreciated
|
|
|
|
|
My advise would be to create a new project as class library. This will be your DAL component.
Then you need to build it with some things in mind:
* You want reusability. I created an interface and inhereted for different providers (mysql, oracle, odbc connectors etc...)
* You need some operations that are able to perform select, update, ... etc. But maybe also less convenient queries (Create table, alter table, ...) Personally I create ExecuteSelect, ExecuteUpdate, ... that takes a string (the sql) and another set ExecuteSelectSafe, ExecuteUpdateSafe, ... that takes the SQL and a list of parameternames and objectvalues.
* I included support for transactions
* I created a class that holds the result. eg the ExecuteXXX class returns that result which holds: a status (OK, FAILED, ...), an exception (if status is failed), the SQL query itself, A dataset, ... etc...
Note that for some providers you'll need the dll.
When built you can or strong-name it and install to the GAC or just reference the dll in any project you want to use it. Don't be lazy on this one, because it will become your bottleneck.
This is the Interface I wrote... Don't blindly copy/paste it. Start from scratch and try to understand what you're doing. (Note: this is an older version, I actually changed the "ENUM return values" into returning a result object containing the status, exception, dataset, ...
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace Framework.Dal
{
public static class DBResult
{
public enum DB_STATUS
{
UNDEFINED = 0,
CONNECTION_FAILED = 1,
CONNECTION_OK = 2,
EXECUTE_FAILED = 3,
EXECUTE_OK = 4,
}
}
public interface IDataBaseConnector
{
void SetConnection_String(string connection_string);
bool TestConnection();
DBResult.DB_STATUS ExecuteSelect(string stmnt);
DBResult.DB_STATUS ExecuteSelectSafe(string command, string[] paramnames, object[] paramvals);
DBResult.DB_STATUS ExecuteUpdate(string stmnt);
DBResult.DB_STATUS ExecuteUpdateSafe(string command, string[] paramnames, object[] paramvals);
DBResult.DB_STATUS ExecuteInsert(string stmnt);
DBResult.DB_STATUS ExecuteInsertSafe(string command, string [] paramnames, object [] paramvals);
DBResult.DB_STATUS ExecuteDelete(string stmnt);
DBResult.DB_STATUS ExecuteDeleteSafe(string command, string[] paramnames, object[] paramvals);
DBResult.DB_STATUS ExecuteStoredProcedure(string sp_name, ArrayList param_names, ArrayList param_values);
DBResult.DB_STATUS ExecuteNonQuery(string stmnt);
DataSet GetDataSet();
string GetLastErrorMessage();
string[] GetTables();
DataColumnCollection GetColumnInformation(string tablename);
int GetNrOfRowsAffected();
}
}
hope this helps.
|
|
|
|
|