Monday, November 28, 2011

Myth Self Note 10: C# WPF - Update UI in other Thread


Problem:
1 - Error Message: "The calling thread cannot access this object because a different thread owns it"
2 - Can't add value or edit listbox while using thread

Search Key:
1 - listbox c# thread used cannot access

Solution:
Use "Dispatcher.Invoke"

'Myth' Example:
1- this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
{
//do something here
}));

Screenshot Example:
2 - call the function from the running thread
"Thread t = new Thread(startScan);
t.Start();"

private void startScan()
{
bla bla bla
ProgressChanged(filesPath);
bla bla bla
}

Help Link:

Thursday, November 10, 2011

Myth Self Note 9: C# WPF - Recursive Loop

Notes:
using recursive loop..

the different is, using
DirectoryInfo.GetFiles()
method, it will search all files in the particular directory then store in an array..then we will loop the array and scan/do function on each item in the array...

the purpose i'm doing the coding manually (recursive loop) is because everytime i encounter a file, i will scan/do some function on it...then store it in the array...(different from GetFiles)

here's my coding..

declare array mypath to store choosen path to be scan for files
private string[] mypath;

store all choosen path in the array
mypath = File.ReadAllLines("scanpath.scn");

this will call the function to search all files in the directory and subdirectory
searchFile();

the function searchFile, loop root directory that i choose in scanpath file just now.
private void searchFile()
{
for (int i = 0; i < mypath.Length ; i++)
{
DirectoryInfo myRoot = new DirectoryInfo(mypath[i]);
string[] myDir = Directory.GetDirectories(mypath[i]);

showFile(myRoot);
recursiveLoop(myDir);

}
}


the function showFile, show/add the list of files in the directory into a listview
private void showFile(DirectoryInfo myDir)
{
string myPath = "";
string myPath2 = "";

foreach (FileInfo file in myDir.GetFiles())
{
myPath = file.ToString();
myPath2 = myDir + "\\" + myPath;

lstScan.Items.Add(myPath2);
string result = doFunction(myPath2);
if (!result.Equals(string.Empty))
{
addIntoListView(myPath, result);
}
}
}

the function recursiveLoop, which will loop and search files in each subdirectory in the directory..and also subdirectory in the subdirectory..untill all files in the root directory and all its subdirectory'subdirectory and so on..
private void recursiveLoop(string[] subdir)
{
foreach (string s in subdir)
{
try
{

DirectoryInfo mySub = new DirectoryInfo(s);
string myPath = "";
string myPath2 = "";

foreach (FileInfo file in mySub.GetFiles())
{
myPath = file.ToString();
myPath2 = mySub + "\\" + myPath;

lstScan.Items.Add(myPath2);
string result = doFunction(myPath2);
if (!result.Equals(string.Empty))
{
addIntoListView(myPath, result);
}
}

string[] myDir = Directory.GetDirectories(s);
recursiveLoop(myDir);
}
catch (Exception c)
{
// Console.WriteLine("Error: " + c.Message);
}
}
}

Monday, September 19, 2011

Myth Self Note 8 : C# - Moving a WPF Window with a WindowStyle of None

Moving a WPF Window when the WindowStyle is set to None.

Some use Thumb and DragDelta. But here i found easier way.

use DragMove();
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}

Ref: http://cloudstore.blogspot.com/2008/06/moving-wpf-window-with-windowstyle-of.html

Friday, September 16, 2011

Bt

central server - tracker
complete file - seed
connected computers with portion of the file - swarm
ordinary computers (not server) that have the file - peers

Wednesday, September 14, 2011

Myth Self Note 7: C# WPF - clear usercontrol


Situation:
i - stkBody children name 'usercontrolA' should be remove when btnStart is click. And 'usercontrolA' will be replace with other usercontrol
ii - usercontrolA : stkMain, stkLeft, stkRight, btnStart

Problem:
To clear the stkBody children (in this case is usercontrolA), use stkBody.Children.clear();
But we can't access stkBody within the 'usercontrolA' body itself.

Solution:
When declaring and adding usercontrolA to the stkBody children, declare btnStart

usercontrolA usercontrolA = new usercontrolA();
stkBody.Children.Add(usercontrolA);
usercontrolA.btnStart.Click += new RoutedEventHandler(btnStart_Click);

void btnScan_Click(object sender, RoutedEventArgs e)
{
stkBody.Children.Clear();
}

themythstoodstill: note for my future self; if don't understand,you should recall back 14/9/11..btnScan, clear parent stack

Source : Link

Tuesday, September 13, 2011

Myth Self Note 6: C# WPF - clear parent

1 - image above is a "usercontrol" which is included in another stack 'stkBody'
2 - motive : want to clear stack 'stkMain' when button 'btnStart' is clicked

Code:
((StackPanel)stkLeft.Parent).Children.Clear;

*stkLeft or stkRight, each can be use because we want to select its parent.

3 - motive : want to remove 'stkLeft' when 'btnStart' is clicked

Code:
((StackPanel)stkLeft.Parent).Children.Remove(stkLeft);


themythstoodstill: in btnStart_Click event, can't access the stkMain.

Monday, September 12, 2011

Myth self note 5: c# WPF - FolderBrowserDialog and listBox

My note on how to open and add folder path to listbox in WPF C#.


1) Right click -> Add Reference (Right click either on the project name "WPF1" or "Reference")
2) .NET -> System.Windows.Forms -> OK


3) using System.Windows.Forms
4) private FolderBrowserDialog openFolder = new FolderBrowserDialog();


5) btnAdd
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
FolderBrowserDialog browseFolder = new FolderBrowserDialog();
openFolder.SelectedPath = "C:\\";
DialogResult result = openFolder.ShowDialog();
if (result.ToString() == "OK")
{
lstPath.Items.Add(openFolder.SelectedPath);
}
}
6) btnRemove
private void btnRmv_Click(object sender, RoutedEventArgs e)
{
lstPath.Items.RemoveAt(lstPath.Items.IndexOf(lstPath.SelectedItem));
}


Example Run

themythstoodstill: note for myth future self, picture/figure explain itself..13/sep/2011

Myth self note 4: Window

Myth Self note; no 4:

var newWindow = new optionPath();
newWindow.Show();

Download Video in Opera

For those whose been using Opera Browser and does not install Orbit Downloader or IDM, and don't know how to download Streaming video (eg; youtube) from Opera.

Here an alternative;
1) http://userscripts.org/scripts/show/33042
Go to this URL, click install.
If so many words appear, just click Ctrl+A on the keyboard to select all the text, then open a Notepad and paste it there. Save As anyname with the extension of .js (eg: user.js)
2) Put the .js anywhere in your computer harddisk. Add the folder path that contain the js to opera script.

Saturday, July 2, 2011

Wadehal

"Naik Moto Tak Cukup Ruang"

Sunday, May 1, 2011

Forgot Joomla Super Administrator Password

It happen again, not remember how many times already..(>.<)


1) open PHPMyadmin or SQL in cpanel,

2) Insert SQL: UPDATE `jos_users` SET `password` = MD5( 'new_password' ) WHERE `jos_users`.`username` = "admin" ;

new_password - replace with the new password

Saturday, April 2, 2011

Thank God

Very grateful to Allah s.w.t.

I'm quite lucky yesterday..


Hampir mengalami kecelakaan jalan raya..XD

Why i'm feeling lucky and grateful?


1. Slalunye aku nek moto ngan Abdul, tp smlm ada Zen so Zen yg nek..

2. Wkt kete langgar moto Abdul, Werm sempat elak..betul2 sipi, dh nk bergesel ngan kete tu..and wkt Werm elak ke kanan, Alhamdulillah xda kenderaan dr arah bertentangan langgar kami..huuu


Tarikh: 1 April 2011

Masa : +- 10.15 Malam

Lokasi : Depan Caltex, Area2 Giant..


Kali kedua kot tgk live depan mata..huuu nasib baik xteruk sgt..cuma yg ngeri skit wkt nmpk darah penuh separuh muka Abdul..


Semoga cepat sembuh pada Zen dan Abdul..AMin..:)

Friday, March 18, 2011

My First Job Opportunity

Before we call you for an interview we would like to see
how deep your knowledge on web development tasks.
If we see that your knowledge is up to par,
we will then set an interview date.


Before 21st March, I need to give them the details of my two LI project, Latihan Mengajar (LM) Web System and Online Publication System. He said it can be details or briefly.

  • Technologies and why it was choosen
  • Development approach
  • any obstacle faced during development
  • any others details

Owh, my first job oppurtunity ever. At least ada gak harapan (walaupun rasanya xdapat kena panggil interview pun rasanya haha).

Anyway thanks to Mr Kamal from Marimore Inc for that opportunity. At least lega skit aku sebab sekurang-kurangnya aku tau kt luar sana ada company yang tak tengok sangat pointer.

Gambate!! I need to have an added value. Mmm, polish up my skill and technique and do the best in FYP. FYP? haha

Tuesday, March 1, 2011

I Love You

(Lyrics by Lee Bernstein [BMI])

I love you
You love me
We're a happy family
With a great big hug
And a kiss from me to you
Won't you say you love me too?

I love you
You love me
We're best friends
Like friends should be
With a great big hug
And a kiss from me to you
Won't you say you love me too?

OS [Infographic]

Some interesting Infographic..About OS..

Klik Link di bawah untuk dapatkan gambar yg lebih jelas..huhu

Source: MakeUseOf.com