The solution involving a table does not work here probably because lstlisting uses itself a table or other kind of tabular to put the numbers on the listing.
So the required solution for this case involves to save the content of the listing into a box, and then use the width of that box to size a \parbox or minipage, and put the original box inside. This new box can be centered by usual methods.
The problem is that lstlisting environment is a "verbatim-like" environment, and putting this kind of environment inside a box causes some problems. Fortunately fancybox package provides the environment Sbox devised for this kind of cases.
So my proposed solution is:
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{fancybox}
\makeatletter
\newenvironment{CenteredBox}{%
\begin{Sbox}}{% Save the content in a box
\end{Sbox}\centerline{\parbox{\wd\@Sbox}{\TheSbox}}}% And output it centered
\makeatother
\begin{document}
\begin{figure}[thp]
\begin{CenteredBox}
\begin{lstlisting}[numbers=left]
My Code
Another line
\end{lstlisting}
\end{CenteredBox}
\caption{Bla}
\end{figure}
\noindent X\hrulefill X\par % This is to see the page width
\end{document}

Note that numbers are not part of the box (they are typeset with some kind of \llap), so they are not taken into account to center it.
tabularlooks odd to me. I'm not sure if this is the best option, but I would go for aminipagesolution, along with thecaptionpackage or something like that. – guillem Dec 04 '12 at 15:46minipageused is equal totextwidth. The problem withminipage, of course, is to automatically determine the horizontal size of the listing. – guillem Dec 04 '12 at 15:53